Supervisor是一个进程监控程序。php
知足的需求是:我如今有一个进程须要每时每刻不断的跑,可是这个进程又有可能因为各类缘由有可能中断。当进程中断的时候我但愿能自动从新启动它,此时,我就须要使用到了Supervisor.python
先弄懂两个命令:web
supervisord : supervisor的服务器端部分,启动supervisor就是运行这个命令服务器
supervisorctl:启动supervisor的命令行窗口swoole
安装(Centos):工具
[root@iZ94xdyrdjmZ etc]# yum install python-setuptools测试
[root@iZ94xdyrdjmZ etc]# easy_install supervisorui
测试是否安装成功:this
[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