1

I am using supervisord to control my processes on Amazon Linux. I want to make use of supervisorctl inside my init script. I have the following so far.

#!/bin/sh
#
# /etc/rc.d/init.d/supervisord
#
# Supervisor is a client/server system that
# allows its users to monitor and control a
# number of processes on UNIX-like operating
# systems.
#
# chkconfig: - 64 36
# description: Supervisor Server
# processname: supervisord

# Source init functions
. /etc/init.d/functions

USER=mv2
RETVAL=0
prog="supervisord"
pidfile=/usr/local/supervisor/logs/supervisord.pid
lockfile="/var/lock/subsys/supervisord"
config=/usr/local/supervisor/conf/supervisord_conf.ini
SUPERVISORCTL=/usr/local/bin/supervisorctl

hard_start()
{
        echo -n $"Starting $prog: "
        daemon --user $USER --pidfile $pidfile /usr/local/bin/supervisord -c $config
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch ${lockfile}
}

hard_stop()
{
        echo -n $"Shutting down $prog: "
        killproc -p ${pidfile} /usr/local/bin/supervisord
        RETVAL=$?
        echo
        if [ $RETVAL -eq 0 ] ; then
            rm -f ${lockfile} ${pidfile}
        fi
}

soft_stop(){
        $SUPERVISORCTL signal SIGTERM all
        RETVAL=$?
                echo
                if [ $RETVAL -eq 0 ] ; then
                    echo "do something"
                fi
}

soft_start(){
        $SUPERVISORCTL start all
        RETVAL=$?
                echo
                if [ $RETVAL -eq 0 ] ; then
                    echo "do something"
                fi
}

reload(){
        echo -ne $"Reloading config file: "\\r
        $($SUPERVISORCTL update) &> /dev/null &
        RETVAL=$?
        echo
            success
}

case "$1" in

  hard-start)
    hard_start
  ;;

  hard-stop)
    hard_stop
  ;;

  status)
        status $prog
  ;;

  restart)
    hard_stop
    hard_start
  ;;

  soft-stop)
    soft_stop
  ;;

  soft-start)
      soft_start
  ;;

  reload)
      reload
  ;;

  *)
    echo "Usage: $0 {hard-start|hard-stop|restart|status|soft-stop|soft-start|soft-restart|reload}"
  ;;

esac

The hard-stop and the hard-start options work well. But, I am not sure how to display the usual success and failed messages for soft-stop, soft-start and the reload option.

kosta
  • 153
  • 2
  • 6

0 Answers0