Skip to content

Instantly share code, notes, and snippets.

@ellisio
Created December 11, 2014 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ellisio/d42ab2f7395bfdaac290 to your computer and use it in GitHub Desktop.
Save ellisio/d42ab2f7395bfdaac290 to your computer and use it in GitHub Desktop.
An init.d script for supervisord
#!/bin/sh
#
# /etc/rc.d/init.d/supervisor
#
# Supervisor is a client/server system that
# allows its users to monitor and control a
# number of processes on UNIX-like operating
# systems.
#
# chkconfig: 345 83 04
# description: Supervisor Server
# processname: supervisord
# config: /etc/supervisor.ini
# pidfile: /var/run/supervisord.pid
#
# Source init functions
. /etc/rc.d/init.d/functions
# Source networking configuration
. /etc/sysconfig/network
# Check networking is up
[ "$NETWORKING" = "no" ] && exit 0
PIDFILE=/var/run/supervisord.pid
OPTIONS="-c /etc/supervisor/supervisor.conf"
WAIT_FOR_SUBPROCESSES=true
start() {
echo $"Starting supervisord: "
if [ -e $PIDFILE ]; then
echo "ALREADY STARTED"
return 1
fi
/usr/bin/supervisord $OPTIONS
/usr/bin/supervisorctl $OPTIONS status
[ -e $PIDFILE ] && touch /var/lock/subsys/supervisord
}
stop() {
echo -n $"Stopping supervisord: "
/usr/bin/supervisorctl $OPTIONS shutdown
if [ -n "$WAIT_FOR_SUBPROCESSES" ]; then
echo "Waiting roughly 60 seconds for $PIDFILE to be removed after child processes exit"
for sleep in 2 2 2 2 4 4 4 4 8 8 8 8 last; do
if [ ! -e $PIDFILE ]; then
echo "supervisord exited as expected in under $total_sleep seconds"
break
else
if [[ $sleep -eq "last" ]]; then
echo "supervisord still working on shutting down. We've waiting roughly 60 seconds, we'll let it do its thing."
return 1
else
sleep $sleep
total_sleep=$(( $total_sleep + $sleep ))
fi
fi
done
fi
rm -rf /var/lock/subsys/supervisord
}
restart() {
stop
start
}
case "$1" in
start)
start
RETVAL=$?
;;
stop)
stop
RETVAL=$?
;;
restart)
restart
RETVAL=$?
;;
reload)
/usr/bin/supervisorctl $OPTIONS reload
RETVAL=$?
;;
condrestart)
[ -f /var/lock/subsys/supervisord ] && restart
RETVAL=$?
;;
status)
/usr/bin/supervisorctl status
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
exit 1
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment