# 安裝
~~~SHELL
yum install supervisor
~~~
# 設置開機啟動
~~~SHELL
systemctl enable supervisord.service
~~~
# 配置文件
supervisord 的配置 文件是`/etc/supervisord.conf`
自定義配置文件目錄是`/etc/supervisord.d`,該目錄下文件已`.ini`為后綴
# 配置進程
例如有個nginx進程設置
~~~SHELL
vim /etc/supervisord.d/nginx.ini
內容如下
[program:nginx]
;directory = /www/lanmps/bin ; 程序的啟動目錄
command = /www/lanmps/bin/nginx start ; 啟動命令,可以看出與手動在命令行啟動的命令是一樣的
autostart = true ; 在 supervisord 啟動的時候也自動啟動
startsecs = 5 ; 啟動 5 秒后沒有異常退出,就當作已經正常啟動了
autorestart = true ; 程序異常退出后自動重啟
startretries = 3 ; 啟動失敗自動重試次數,默認是 3
user = www ; 用哪個用戶啟動
redirect_stderr = true ; 把 stderr 重定向到 stdout,默認 false
stdout_logfile_maxbytes = 20MB ; stdout 日志文件大小,默認 50MB
stdout_logfile_backups = 20 ; stdout 日志文件備份數
; stdout 日志文件,需要注意當指定目錄不存在時無法正常啟動,所以需要手動創建目錄(supervisord 會自動創建日志文件)
stdout_logfile = /www/logs/usercenter_stdout.log
stopasgroup=false ;默認為false,進程被殺死時,是否向這個進程組發送stop信號,包括子進程
killasgroup=false ;默認為false,向進程組發送kill信號,包括子進程
; 可以通過 environment 來添加需要的環境變量,一種常見的用法是修改 PYTHONPATH
; environment=PYTHONPATH=$PYTHONPATH:/path/to/somewhere
~~~
[program:sms_1902]
command = python /www/wwwroot/market_1802_api/market_1.py
autostart = true
startsecs = 5
autorestart = true
startretries = 3
user = root
redirect_stderr = true
stdout_logfile_maxbytes = 20MB
stdout_logfile_backups = 20
;stdout 日志文件,需要注意當指定目錄不存在時無法正常啟動,所以需要手動創建目錄(supervisord 會自動創建日志文件)
stdout_logfile = /www/wwwroot/market_1802.log
stopasgroup=false
killasgroup=false
# supervisord 客戶端管理命令
~~~SHELL
supervisorctl status # 狀態
supervisorctl stop nginx #關閉 nginx
supervisorctl start nginx #啟動 nginx
supervisorctl restart nginx #重啟 nginx
supervisorctl reread
supervisorctl update #更新新的配置
~~~
# 其他
~~~SHELL
supervisord:服務守護進程
supervisorctl:命令行客戶端
~~~