Supervisor 安裝與配置

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

相關文章
相關標籤/搜索