Supervisor是一个进程监控程序。
满足的需求是:我现在有一个进程需要每时每刻不断的跑,但是这个进程又有可能由于各种原因有可能中断。当进程中断的时候我希望能自动重新启动它,此时,我就需要使用到了Supervisor.
先弄懂两个命令:
supervisord : supervisor的服务器端部分,启动supervisor就是运行这个命令
supervisorctl:启动supervisor的命令行窗口
安装(Centos):
[root@iZ94xdyrdjmZ etc]# yum install python-setuptools
[root@iZ94xdyrdjmZ etc]# easy_install supervisor
测试是否安装成功:
[root@iZ94xdyrdjmZ etc]# echo_supervisord_conf
会显示以下内容,其实是一个配置模版:
创建配置文件:
[root@iZ94xdyrdjmZ etc]# echo_supervisord_conf > /etc/supervisord.conf
修改配置文件:
在supervisord.conf最后增加(分号后边的表示注释,可以不写):
[include]
files = /etc/subversion/*.ini
在 /etc/subversion/ 目录下建立 swoole-crontab.ini 文件
[program:swoole-crontab]
command=php /alidata/www/didi365/Crontab/main.php -d -s start
autorstart=true
autorestart=true
stdout_logfile=/tmp/supervisor.log
[Web配置]
[inet_http_server] ; inet (TCP) server disabled by default
port=*: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))
如果配置了用户名和密码,就需要输入用户名和密码才能进入web界面
[启动supervisord]
[root@iZ94xdyrdjmZ etc]# supervisord
可能会输出一堆信息出来
/usr/lib/python2.6/site-packages/supervisor-3.1.3-py2.6.egg/supervisor/options.py:296: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security.
'Supervisord is running as root and it is searching '
/usr/lib/python2.6/site-packages/supervisor-3.1.3-py2.6.egg/supervisor/options.py:383: DeprecationWarning: Parameters to load are deprecated. Call .resolve and .require separately.
return pkg_resources.EntryPoint.parse("x="+spec).load(False)
不用管它
[root@iZ94xdyrdjmZ etc]# ps -ef | grep supervis
root 450 9437 0 11:31 pts/0 00:00:00 grep supervis
root 18836 1 0 10:02 ? 00:00:01 /usr/bin/python /usr/bin/supervisord
[命令行管理工具]
[root@iZ94xdyrdjmZ etc]# supervisorctl status
swoole-crontab RUNNING pid 29981, uptime 0:33:05
如果修改了 /etc/supervisord.conf ,需要执行 supervisorctl reload 来重新加载配置文件
Error: Another program is already listening on a port that one of our HTTP servers is configured to use. Shut this program down first before starting
解决方法:
find / -name supervisor.sock
unlink /name/supervisor.sock
设置开机自动启动
vi /etc/rc.local
添加 supervisord