1. 程式人生 > >Centos6.7 Supervisor程序配置管理

Centos6.7 Supervisor程序配置管理

下載安裝
#wget http://pypi.python.org/packages/source/s/supervisor/supervisor-3.0b1.tar.gz
 #tar -zxvf supervisor-3.0b1.tar.gz 
 #cd supervisor-3.0b1
 #python setup.py install
 #echo_supervisord_conf > /etc/supervisord.conf

寫啟動檔案
vi  /etc/init.d/supervisord 
寫下面內容================================================
#! /bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
PROGNAME=supervisord
DAEMON=/usr/bin/$PROGNAME
CONFIG=/etc/$PROGNAME.conf
PIDFILE=/tmp/$PROGNAME.pid
DESC="supervisord daemon"
SCRIPTNAME=/etc/init.d/$PROGNAME
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
start()
{
        echo -n "Starting $DESC: $PROGNAME"
        $DAEMON -c $CONFIG
        echo "..."
}
stop()
{
        echo -n "Stopping $DESC: $PROGNAME"
        supervisor_pid=$(cat $PIDFILE)
        kill -15 $supervisor_pid
        echo "..."
}
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        stop
        start
        ;;
  *)
        echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2
        exit 1
        ;;
esac
exit 0

加許可權
chmod -R 777 /etc/init.d/supervisord 

修改配置檔案 新增程序(紅色字型)
=====內容省略
; The below sample program section shows all possible program subsection values,
; create one or more 'real' program: sections to be able to control them under
; supervisor.
<span style="color:#FF0000;">[program:pmapp]
command=python /var/www/manage.py runserver 0:8000
autorestart=true
stdout_logfile=/tmp/out.log
stderr_logfile=/tmp/err.log
</span>
;[program:theprogramname]
;command=/bin/cat              ; the program (relative uses PATH, can take args)
;process_name=%(program_name)s ; process_name expr (default %(program_name)s)
;numprocs=1                    ; number of processes copies to start (def 1)
;directory=/tmp                ; directory to cwd to before exec (def no cwd)
;umask=022                     ; umask for process (default None)
;priority=999                  ; the relative start priority (default 999)
;autostart=true                ; star
=====內容省略

重起服務
[[email protected] ~]# service supervisord restart
Stopping supervisord daemon: supervisord...
Starting supervisord daemon: supervisord...

檢查是否成功
[[email protected] ~]# netstat -antp |grep 8000
tcp        0      0 0.0.0.0:8000                0.0.0.0:*                   LISTEN      10207/python      

開啟WEB管理 vi /etc/supervisord.conf 把紅色註釋去掉
=====內容省略
[unix_http_server]
file=/tmp/supervisor.sock   ; (the path to the socket file)
;chmod=0700                 ; socket file mode (default 0700)
;chown=nobody:nogroup       ; socket file uid:gid owner
;username=user              ; (default is no username (open server))
;password=123               ; (default is no password (open server))

<span style="color:#FF0000;">[inet_http_server]         ; inet (TCP) server disabled by default
port=0.0.0.0:9001        ; (ip_address:port specifier, *:port for all iface)
username=user              ; (default is no username (open server))
password=123               ; (default is no password (open server))</span>

[supervisord]
logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB        ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10           ; (num of main logfile rotation backups;default 10)
loglevel=info                ; (
=====內容省略

重起服務
[[email protected] ~]# service supervisord restart
Stopping supervisord daemon: supervisord...
Starting supervisord daemon: supervisord...

是否啟動成功
[[email protected] ~]# netstat -antp |grep 9001
tcp        0      0 127.0.0.1:9001              0.0.0.0:*                   LISTEN      10311/python