supervisord是用Python開發的一個進程管理工具
1、直接使用pip直接安裝
pip install supervisor
2、生成配置文件
echo_supervisord_conf > /etc/supervisord.conf
3、最后一行添加配置,方便管理自定義進程
[include]
files = /etc/supervisord.d/*.ini
4、創建自定義腳本文件
mkdir -p /etc/supervisord.d
vim /etc/supervisord.d/projectname.ini
#/etc/supervisord.d/projectname.ini
[program:projectname]
directory=/hello #項目路徑
command=/venv/bin/python3 hello.py #腳本命令
autostart=true #是否隨supervisor啟動
autorestart=true #是否在意外關閉后重啟
startretires=3 #嘗試啟動次數
user=root #指定用戶執行
[fcgi-program:uvicorn]
socket= #supervisor的通信地址
directory=項目路徑
command=命令
autostart=true
autorestart=true
startretries=3
user=root
numprocs=supervisord的進程數
process_name=%(program_name)s_%(process_num)02d #多個進程,需要設置不同的進程名字
stderr_logfile=/www/wwwroot/qiuguantxApp/logs/error.log #日志
stdout_logfile=/www/wwwroot/qiuguantxApp/logs/out.log
5、啟動supervisor
supervisord -c /etc/supervisord.conf
6、supervisorctl管理命令
supervisorctl start projectname #啟動進程
supervisorctl stop projectname #結束進程
supervisorctl restart projectname #重啟進程
supervisorctl stop all #停止所有進程
supervisorctl update #更新變動的進程配置
supervisorctl reload #重啟所有進程
supervisorctl status #查看進程狀態