#!/bin/bash
### BEGIN INIT INFO
# Provides:          supervisor
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Supervisor init script
# Description:       Supervisor is a client/server system for controlling
#                    process state under UNIX-like operating systems.
### END INIT INFO

SUPERVISORD=/usr/bin/supervisord
SUPERVISORCTL=/usr/bin/supervisorctl
PIDFILE=/var/run/supervisord.pid
CONF=/etc/supervisor/supervisord.conf

. /lib/lsb/init-functions

case "$1" in
  start)
    log_daemon_msg "Starting supervisor" "supervisord"
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $SUPERVISORD -- -c $CONF
    log_end_msg $?
    ;;
  stop)
    log_daemon_msg "Stopping supervisor" "supervisord"
    start-stop-daemon --stop --quiet --pidfile $PIDFILE
    log_end_msg $?
    ;;
  restart)
    $0 stop
    sleep 1
    $0 start
    ;;
  status)
    status_of_proc -p $PIDFILE $SUPERVISORD supervisor && exit 0 || exit $?
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|status}"
    exit 1
    ;;
esac

exit 0
