Supervisor 安裝與配置


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM