程序运行过程中可能由于外部原因造成任务fail,需要随时监控及时restart,supervisor可以完成这一任务.
一 安装
Install supervisord
sudo yum install python-setuptools
sudo easy_install pip
sudo pip install supervisor
安装完成后,编辑默认配置文件
sudo echo_supervisord_conf > /etc/supervisord.conf
|
二 使用与配置
Supervisord Config
编辑 /etc/supervisord.conf
[program:example-
8888
]
command=/var/www/example/server.py --port=
8888
autostart=
true
; supervisord守护程序启动时自动启动tornado
autorestart=
true
; supervisord守护程序重启时自动重启tornado
redirect_stderr=
true
; 将stderr重定向到stdout
启动: supervisord /usr/local/bin/supervisord -c /etc/supervisord.conf
查看: supervisordctl :
showaction_process RUNNING pid
6794
, uptime
0
:
29
:
55
|
三 Case:
对于自己定义的shell任务,用supervisord配置时需要注意:
-
命令用nohup形式启动,启动才能处于Running状态
-
supervisord配置的任务stop时本身不会kill 子进程,需要用pidproxy启动
以下为成功配置自身任务的一个case:
case:showaction_process
[program:showaction_process]
command=/usr/local/bin/pidproxy ~/tool/useraction/pidfile /usr/bin/nohup ~/tool/useraction/process_showaction.sh2>&1>~/tool/useraction/nohup_process_showaction.out &
autostart=
true
autorestart=
true
stopasgroup=
true
startsecs=
0
startretries=
999
log_stdout=
true
log_stderr=
true
redirect_stderr=
false
stdout_logfile=/var/log/recommendation/showaction_process-supervisor-out
stdout_logfile_maxbytes=100MB
stdout_logfile_backups=
10
stdout_events_enabled=
true
stderr_logfile=/var/log/recommendation/showaction_process-supervisor-err
stderr_logfile_maxbytes=100MB
stderr_logfile_backups=
10
stderr_events_enabled=
true
|
[附录]参考文档:
-
安装supvisord:http://supervisord.org/installing.html
-
配置supvisord:http://supervisord.org/configuration.html
-
使用pidproxy配置kill子程序:http://supervisord.org/subprocess.html