LoginSignup
12
11

More than 5 years have passed since last update.

Supervisorの起動スクリプト

Posted at

最新版の Supervisor を pip でインストールした際に起動スクリプトが無かったので、こちらを参考に作成しました。

/etc/init.d/supervisord
# Source function library.
. /etc/rc.d/init.d/functions

supervisorctl="/usr/bin/supervisorctl"
supervisord="/usr/bin/supervisord"
name="supervisor-python"

[ -f $supervisord ] || exit 1
[ -f $supervisorctl ] || exit 1

RETVAL=0

start() {
    echo -n "Starting $name: "
    $supervisord -c /etc/supervisord.conf
    RETVAL=$?
    if [ $RETVAL -eq 0 ]
    then
      echo -e "SUCCESS"
    else
      echo -e "FAILED"
    fi
    return $RETVAL
}

stop() {
    echo -n "Stopping $name: "
    $supervisorctl shutdown
    RETVAL=$?
    if [ $RETVAL -eq 0 ]
    then
      echo -e "SUCCESS"
    else
      echo -e "FAILED"
    fi
    return $RETVAL
}

status() {
  $supervisorctl status
}

case "$1" in
    start)
        start
        ;;

    stop)
        stop
        ;;

    restart)
        stop
        count=0
        while [ $count -ne 30 ]
        do
            ret=`$supervisorctl status > /dev/null 2>&1 ; echo $?`
            if [ $ret -eq 0 ]
            then
                echo -e ""
                break
            fi
            echo -n "."
            count=`expr $count + 1`
            sleep 1s
        done
        start
        ;;

    status)
        status
        ;;
esac

exit $REVAL
12
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
11