Service status not working

1.7k views Asked by At

I have the following code for a service that I'm trying to have automatically start on boot.

#!/bin/sh
# Source function library.
. /etc/rc.d/init.d/functions

RETVAL=0

prog='foo'
exec="/usr/sbin/$prog"
pidfile="/var/run/$prog.pid"
lock_file="/var/lock/subsys/$prog"
logfile="/var/log/$prog"

if [ -f /etc/default/foo ]; then
  . /etc/default/foo
fi

if [ -z $QUEUE_TYPE ]; then
  echo 'ENV variable QUEUE_TYPE has not been set, please set it in /etc/default/foo'
  exit 1
fi

get_pid() {
  cat "$pidfile"
}

is_running() {
  [ -f "$pidfile" ] && ps `get_pid` > /dev/null 2>&1
}

case "$1" in
  start)
    echo -n "Starting Consul daemon: "
    #
    daemon --pidfile $pidfile --check foo --user my-user "my app stuff here"
    echo
    ;;
  stop)
    echo -n 'Stopping Consul daemon: '
    killproc foo
    echo
    ;;
  status)
    status $pidfile
    RETVAL=$?
    #status -p $pidfile -l $prog
    #[ $RETVAL -eq 0 ] && RETVAL=$?
    #RETVAL=$?
    #if is_running; then
    #  echo 'Running'
    #else
    #  echo 'Not Running'
    #fi
    #status foo
    #RETVAL=$?
    ;;
  restart)
    $0 stop
    $0 start
    RETVAL=$?
    ;;
  *)
    echo 'Usage: foo {start|stop|status|restart}'
    exit 1
esac

exit $RETVAL

When I run sudo service foo status it says that it hasn't been started which is correct. After running sudo service foo start and then running the status command, it tells me that the service hasn't been started. I'm not sure what is causing this to happen. I looked at the configurations for other init.d scripts to see how they were handling this and tried to follow their lead. Is there something obvious here that I'm doing wrong or something else that I may be unaware of that's causing this problem?

0

There are 0 answers