1、介紹supervisor
Supervisor是用Python開發(fā)的一個client/server服務(wù),是Linux/Unix系統(tǒng)下的一個進程管理工具,不支持Windows系統(tǒng)。它可以很方便的監(jiān)聽、啟動、停止、重啟一個或多個進程。用Supervisor管理的進程,當(dāng)一個進程意外被殺死,supervisort監(jiān)聽到進程死后,會自動將它重新拉起,很方便的做到進程自動恢復(fù)的功能,不再需要自己寫shell腳本來控制。
2、安裝環(huán)境
# 安裝 python環(huán)境
yum install python-setuptools
# 安裝 Supervisor
easy_install supervisor
3、配置Supervisor
# 新建配置目錄命令:
mkdir /etc/supervisor
#生成supervisor的初始化配置文件 :
echo_supervisord_conf > /etc/supervisor/supervisord.conf
編輯配置supervisord.conf
vim supervisord.conf
主要是打開網(wǎng)絡(luò)訪問、默認啟動配置目錄


# 創(chuàng)建配置目錄
mkdir /etc/supervisor/conf.d
# 進入目錄
cd conf.d
#創(chuàng)建一個WebApplication1.conf配置
vi WebApplication1.conf
# 創(chuàng)建程序啟動配置
# 進程名稱
[program:WebApplication1]
# 執(zhí)行命令
command=dotnet WebApplication1.dll
# 執(zhí)行目錄
directory=/root/aspnetcoreapi
# 掉線是否自動重啟
autorestart=true
# 日志信息
stderr_logfile=/var/log/WebApplication1.err.log
stdout_logfile=/var/log/WebApplication1.out.log
# 環(huán)境.Net core
environment=ASPNETCORE_ENVIRONMENT=Production
# 執(zhí)行用戶
user=root
stopsignal=INT
4、啟動Supervisor
# 啟動Supervisor
supervisord -c /etc/supervisor/supervisord.conf
#查看狀態(tài)
supervisorctl status

5、bash終端控制
#啟動Supervisor
supervisord -c /etc/supervisor/supervisord.conf
# 查看狀態(tài)
supervisorctl status
# 停止某個服務(wù)
supervisorctl stop WebApplication1
# 開始某個服務(wù)
supervisorctl start WebApplication1
# 重啟某個服務(wù)
supervisorctl restart WebApplication1
# 重啟Supervisor
supervisorctl reload
# 修改Supervisor
supervisorctl update
6、將supervisor配置為開機自啟動服務(wù)
# 編輯服務(wù)文件
vim /usr/lib/systemd/system/supervisord.service
# 內(nèi)容
[Unit]
Description=Supervisor
[Service]
Type=forking
PIDFile=/var/run/supervisord.pid
ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf
ExecStop=/usr/bin/supervisorctl shutdown
ExecReload=/usr/bin/supervisorctl reload
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
# 保存退出 啟動服務(wù)
systemctl enable supervisord
# 查看啟動狀態(tài) 返回enabled成功
systemctl is-enabled supervisord
#成功之后,就可以使用如下命令管理supervisor服務(wù)了
# 停止
systemctl stop supervisord
# 啟動
systemctl start supervisord
# 狀態(tài)
systemctl status supervisord
# 重載
systemctl reload supervisord
# 重啟
systemctl restart supervisord
我們最后也可以看到我們將進程殺死之后馬上會啟動一個新的進程啟動程序

最后我們可以通過我們配置的網(wǎng)絡(luò)地址訪問了,可以看到所有的程序方便管理

|