supervisor部署python專案
阿新 • • 發佈:2021-07-09
1. 安裝supervisor
supervisor可以幫助我們盯著python程式,哪怕是python程式不小心掛掉了,supervisor也會幫我們立即啟起來,首先開始安裝
pip install supervisor
2. 生成配置檔案
supervisor通過配置檔案來控制python檔案
echo_supervisord_conf > ./supervisord.conf
3. 修改配置檔案
比如,我的目的是讓supervisor保障/test/下的test1.py和test2.py能持續執行
首先通過which python確定使用哪個python
>>> which python /opt/conda/envs/py374/bin/python
…… ;[include] ;files = relative/directory/*.ini # 直接跳到最後新增如下程式碼(我的python絕對路徑是
/opt/conda/envs/py374/bin/python
) #專案1 [program:partion-1] # 給個名字 directory=/test/ # python程式所在目錄 command= /opt/conda/envs/py374/bin/python test1.py # 開始等待時間 startsecs=0 # 停止等待時間 stopwaitsecs=0 autorestart=true # 設定為守護程序 daemon=true #專案2 [program:partion-2] # 給個名字 directory=/test/ # python程式所在目錄 command= /opt/conda/envs/py374/bin/python test2.py # 開始等待時間 startsecs=0 # 停止等待時間 stopwaitsecs=0 autorestart=true # 設定為守護程序 daemon=true
4. 首次啟動
supervisord -c supervisord.conf
此時test1.py, test2.py 已經開始運行了
5. 後續操作
supervisorctl -c supervisord.conf
停止程式:stop all
啟動程式:start all
過載:reload