1、安裝Python包管理工具(easy_install)
yum install python-setuptools
2、安裝Supervisor
easy_install supervisor
##配置文件
- 通過運行echo_supervisord_conf程序生成supervisor的初始化配置文件,如下所示:
mkdir /etc/supervisor
echo_supervisord_conf > /etc/supervisor/supervisord.conf
- 然後查看路徑下的supervisord.conf。在文件尾部添加如下配置。
;[include]
;files = relative/directory/*.ini
;conf.d 爲配置表目錄的文件夾,需要手動創建
[include]
files = conf.d/*.conf
- 爲你的程序創建一個.conf文件,放在目錄"/etc/supervisor/conf.d/"下。
[program:MGToastServer] ;程序名稱,終端控制時需要的標識
command=dotnet MGToastServer.dll ; 運行程序的命令
directory=/root/文檔/toastServer/ ; 命令執行的目錄
autorestart=true ; 程序意外退出是否自動重啓
stderr_logfile=/var/log/MGToastServer.err.log ; 錯誤日誌文件
stdout_logfile=/var/log/MGToastServer.out.log ; 輸出日誌文件
environment=ASPNETCORE_ENVIRONMENT=Production ; 進程環境變量
user=root ; 進程執行的用戶身份
stopsignal=INT
- 運行supervisord,查看是否生效
supervisord -c /etc/supervisor/supervisord.conf
ps -ef | grep MGToastServer
成功後的效果:
ps 如果服務已啓動,修改配置文件可用
supervisorctl reload
命令來使其生效
配置Supervisor開機啓動
- 新建一個“supervisord.service”文件
# dservice for systemd (CentOS 7.0+)
# by ET-CS (https://github.com/ET-CS)
[Unit]
Description=Supervisor daemon
[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorctl shutdown
ExecReload=/usr/bin/supervisorctl reload
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
-
將文件拷貝至"/usr/lib/systemd/system/supervisord.service"
-
執行命令
systemctl enable supervisord
- 執行命令來驗證是否爲開機啓動
systemctl is-enabled supervisord
配置完成啦.
常用的相關管理命令
supervisorctl restart <application name> ;重啓指定應用
supervisorctl stop <application name> ;停止指定應用
supervisorctl start <application name> ;啓動指定應用
supervisorctl restart all ;重啓所有應用
supervisorctl stop all ;停止所有應用
supervisorctl start all ;啓動所有應用