网站首页Linux相关

Centos6配置supervisor开机启动

发布时间:2017-02-07编辑:fc不将就阅读(1477

    centos6.8配置supervisor自启动脚本。

    参考:github.com/Supervisor/initscripts/blob/master/redhat-init-equeffelec

    步骤

    1:创建vim /etc/init.d/supervisord文件

    # 这些请根据自己的路径填写
    supervisorctl=/usr/bin/supervisorctl  supervisorctl命令的位置
    supervisord=${SUPERVISORD-/usr/bin/supervisord} supervisord命令位置
    prog=supervisord
    pidfile=${PIDFILE-/tmp/supervisord.pid}
    lockfile=${LOCKFILE-/var/lock/subsys/supervisord}
    STOP_TIMEOUT=${STOP_TIMEOUT-60}
    OPTIONS="${OPTIONS--c /home/admin/setting/judge/supervisord.conf}" 配置文件的位置
    RETVAL=0 
    USER=admin 启动的用户名

    内容为:

    #!/bin/bash
    
    # chkconfig:    345 83 04
    # description: Supervisor is a client/server system that allows \
    #   its users to monitor and control a number of processes on \
    #   UNIX-like operating systems.
    # processname: supervisord
    # config: /etc/supervisord.conf
    # config: /etc/sysconfig/supervisord
    # pidfile: /var/run/supervisord.pid
    #
    ### BEGIN INIT INFO
    # Provides: supervisord
    # Required-Start: $all
    # Required-Stop: $all
    # Short-Description: start and stop Supervisor process control system
    # Description: Supervisor is a client/server system that allows
    #   its users to monitor and control a number of processes on
    #   UNIX-like operating systems.
    ### END INIT INFO
    
    # Source function library
    . /etc/rc.d/init.d/functions
    
    # Source system settings
    if [ -f /etc/sysconfig/supervisord ]; then
        . /etc/sysconfig/supervisord
    fi
    
    # Path to the supervisorctl script, server binary,
    # and short-form for messages.
    supervisorctl=/usr/bin/supervisorctl
    supervisord=${SUPERVISORD-/usr/bin/supervisord}
    prog=supervisord
    pidfile=${PIDFILE-/tmp/supervisord.pid}
    lockfile=${LOCKFILE-/var/lock/subsys/supervisord}
    STOP_TIMEOUT=${STOP_TIMEOUT-60}
    OPTIONS="${OPTIONS--c /home/admin/setting/judge/supervisord.conf}"
    RETVAL=0
    USER=admin
    
    start() {
        echo -n $"Starting $prog: "
        daemon --user $USER --pidfile=${pidfile} $supervisord $OPTIONS
        RETVAL=$?
        echo
        if [ $RETVAL -eq 0 ]; then
            touch ${lockfile}
            $supervisorctl $OPTIONS status
        fi
        return $RETVAL
    }
    
    stop() {
        echo -n $"Stopping $prog: "
        killproc -p ${pidfile} -d ${STOP_TIMEOUT} $supervisord
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -rf ${lockfile} ${pidfile}
    }
    
    reload() {
        echo -n $"Reloading $prog: "
        LSB=1 killproc -p $pidfile $supervisord -HUP
        RETVAL=$?
        echo
        if [ $RETVAL -eq 7 ]; then
            failure $"$prog reload"
        else
            $supervisorctl $OPTIONS status
        fi
    }
    
    restart() {
        stop
        start
    }
    
    case "$1" in
        start)
            start
            ;;
        stop)
            stop
            ;;
        status)
            status -p ${pidfile} $supervisord
            RETVAL=$?
            [ $RETVAL -eq 0 ] && $supervisorctl $OPTIONS status
            ;;
        restart)
            restart
            ;;
        condrestart|try-restart)
            if status -p ${pidfile} $supervisord >&/dev/null; then
              stop
              start
            fi
            ;;
        force-reload|reload)
            reload
            ;;
        *)
            echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload}"
            RETVAL=2
    esac
    
    exit $RETVAL

    2:修改权限

    $ sudo chmod 777 /etc/init.d/supervisord

    3:配置开启启动

    $ sudo chkconfig supervisord on
    #下面命令查看是否配置成功
    $sudo chkconfig --list | grep  supervisord
    supervisord    	0:关闭	1:关闭	2:启用	3:启用	4:启用	5:启用	6:关闭

    4:验证

    重启服务器之后查看是否有supervisor进程

    $ sudo reboot
    
    $ ps -ef|grep supervisord
    admin     1325     1  0 15:24 ?        00:00:00 /usr/bin/python /usr/bin/supervisord -c /home/admin/setting/judge/supervisord.conf