Supervisor是什么
Supervisor是Python编写的守护进程,有如下功能:
1, 管理其他进程,被管理的进程挂掉的时候,主动拉起;
官方地址: http://supervisord.org/introduction.html
安装:
我的环境是python 2.6.6(根据不同的版本需要不同的python版本)
Centos 6.6
yum install -y supervisor
配置
设置开机启动:
chkconfig supervisord on
配置文件:
/etc/supervisord.conf
[program:inception]
command=/usr/local/bin/Inception --defaults-file=/etc/inc.cnf
autostart=true ; start at supervisord start (default: true)
autorestart=true ; retstart at unexpected quit (default: true)
startsecs=10 ; number of secs prog must stay running (def. 10)
startretries=3 ; max # of serial start failures (default 3)
log_stdout=true ; if true, log program stdout (default true)
log_stderr=true ; if true, log program stderr (def false)
logfile=/var/log/cat.log ; child log path, use NONE for none; default AUTO
logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
logfile_backups=10 ; # of logfile backups (default 10)
有2个程序:supervisord 和 supervisorctl, supervisord是服务端程序,supervisorctl是客户端程序;
启动程序: service supervisord start
查看服务状态
[root@93a17e41-ee44-4c53-8432-b196632b8891 ~]# service supervisord status
supervisord (pid 274821) is running...
supervisorctl 进入客户端管理程序;
[root@93a17e41-ee44-4c53-8432-b196632b8891 ~]# supervisorctl
inception RUNNING pid 276128, uptime 0:41:49
supervisor> help
Documented commands (type help <topic>):
========================================
EOF exit maintail quit restart start stop
clear help open reload shutdown status tail
supervisor>
supervisor> status
inception RUNNING pid 276128, uptime 0:42:08
supervisor>
验证:
手动kill inception进程,看是否会被supervisord自动拉起;
ps 查看进程ID是 276128,将其KILL
[root@93a17e41-ee44-4c53-8432-b196632b8891 ~]# ps -ef | grep inc
root 276128 274821 0 16:06 ? 00:00:05 /usr/local/bin/Inception --defaults-file=/etc/inc.cnf
root 305510 272078 0 16:49 pts/0 00:00:00 grep inc
[root@93a17e41-ee44-4c53-8432-b196632b8891 ~]#
[root@93a17e41-ee44-4c53-8432-b196632b8891 ~]# kill -9 276128
supervisorctl登陆客户端,status查看状态; 显示STARTING;
等候startsecs-=10s 后进程被拉起来
supervisor> status
inception STARTING
supervisor> status
inception STARTING
supervisor> status
inception STARTING
supervisor> status
inception RUNNING pid 305882, uptime 0:00:11
supervisor> status
inception RUNNING pid 305882, uptime 0:00:13
ps命令查看确认进程确实已经被拉起来了;
[root@93a17e41-ee44-4c53-8432-b196632b8891 ~]# ps -ef | grep inc
root 305882 274821 0 16:50 ? 00:00:00 /usr/local/bin/Inception --defaults-file=/etc/inc.cnf
root 306104 272078 0 16:50 pts/0 00:00:00 grep inc