1,安裝:pip install supervisorpython
2,生成配置文件:echo_supervisord_conf > /etc/supervisord.confweb
3,編輯配置文件:vim /etc/supervisord.confvim
修改最後兩行,去掉前面的分號。測試
這是存放進被管理的進程的配置文件spa
4,開啓web控制檯:找到以下幾行,去掉註釋debug
[program:test1] user=root directory=/usr/local/test/ command=/usr/local/bin/python /usr/local/test/test.py autostart=true autorestart=true loglevel=debug log_stderr=true stdout_logfile=/var/log/test1.log redirect_stderr=true
如需管理多個進程,那就配置多個文件rest
6,啓動superv日誌
補充:添加supervisord服務,設置開機啓動code
上面安裝的沒有生成supervisord這個服務,本身參考改一個server
文件以下:vim /etc/init.d/supervisord
#!/bin/sh ## ## /etc/rc.d/init.d/supervisord ## #supervisor is a client/server system that # allows its users to monitor and control a # number of processes on UNIX-like operating # systems. # # chkconfig: - 64 36 # description: Supervisor Server # processname: supervisord # Source init functions . /etc/rc.d/init.d/functions prog="supervisord" prefix="/usr/local/" exec_prefix="${prefix}" PIDFILE="/var/run/supervisord.pid" CONFIG="/etc/supervisord.conf" prog_bin="${exec_prefix}bin/supervisord -c $CONFIG " function log_success_msg() { echo "$@" "[ OK ]" } function log_failure_msg() { echo "$@" "[ OK ]" } start() { #echo -n $"Starting $prog: " #daemon $prog_bin --pidfile $PIDFILE #[ -f $PIDFILE ] && success $"$prog startup" || failure $"$prog failed" #echo if [ ! -r $CONFIG ]; then log_failure_msg "config file doesn't exist (or you don't have permission to view)" exit 4 fi if [ -e $PIDFILE ]; then PID="$(pgrep -f $PIDFILE)" if test -n "$PID" && kill -0 "$PID" &>/dev/null; then # If the status is SUCCESS then don't need to start again. log_failure_msg "$NAME process is running" exit 0 fi fi log_success_msg "Starting the process" "$prog" daemon $prog_bin --pidfile $PIDFILE log_success_msg "$prog process was started" } stop() { echo -n $"Shutting down $prog: " [ -f $PIDFILE ] && killproc $prog || success $"$prog shutdown" echo } case "$1" in start) start ;; stop) stop ;; status) status $prog ;; restart) stop start ;; *) echo "Usage: $0 {start|stop|restart|status}" ;; esac
文件中的prefix和config變量記得檢查下
給文件執行權限
chmod -R 755 /etc/init.d/supervisord
添加服務
chkconfig --add supervisord
設置開機啓動
chkconfig supervisord on
測試:
測試前先把以前啓動的supervisord進程和子進程殺掉,kill -9
而後
service supervisord start
service supervisord stop
管理的子進程也會一併起來和殺死