Supervisor 官網
Supervisor 安裝
- Centos 7.X 安裝 supervisord
yum install supervisor
Supervisor 守護進程
supervisor.conf 配置
- supervisor.conf 文件路徑:/etc/supervisord.d
- 主要配置包含子文件的配置,同級 conf.d 目錄,以 .ini 結尾的配置文件
[include]
files = ./conf.d/*.ini
新建 supervisor ini 文件
在 /etc/supervisord.d/conf.d 目錄,新建 .ini 文件,如下
Supervisor 守護 DJCelery 配置文件
- 1. python manage.py celery -A HttpRunnerManager worker --loglevel=info # 啟動 worker(Celery 職程服務器)
- 2. python manage.py celery beat --loglevel=info # 啟動定時任務監聽器
- 3. celery flower --address=0.0.0.0 --port=5555 # 啟動任務監控后
celery_beat.ini
[root@gitlab conf.d]# cat celery_beat.ini
[program:CeleryBeat]
#CelertBeat 為程序的名稱
command=/root/.envs/hrm/bin/python manage.py celery beat --loglevel=info
#需要執行的命令
directory=/root/TestProject/HttpRunnerManager
#命令執行的目錄
#environment=ASPNETCORE__ENVIRONMENT=Production
#環境變量
user=root
#用戶
stopsignal=INT
autostart=true
#是否自啟動
autorestart=true
#是否自動重啟
startsecs=3
#自動重啟時間間隔(s)
stderr_logfile=/root/TestProject/logs/celerybeat.err.log
#錯誤日志文件
stdout_logfile=/root/TestProject/logs/celerybeat.out.log
#輸出日志文件
celery_worker.ini
[root@gitlab conf.d]# cat celery_worker.ini
[program:CeleryWorker]
#CeleryWork 為程序的名稱
command=/root/.envs/hrm/bin/python manage.py celery -A HttpRunnerManager worker --loglevel=info
#需要執行的命令
directory=/root/TestProject/HttpRunnerManager
#命令執行的目錄
#environment=ASPNETCORE__ENVIRONMENT=Production
#環境變量
user=root
#用戶
stopsignal=INT
autostart=true
#是否自啟動
autorestart=true
#是否自動重啟
startsecs=3
#自動重啟時間間隔(s)
stderr_logfile=/root/TestProject/logs/celeryworker.err.log
#錯誤日志文件
stdout_logfile=/root/TestProject/logs/celeryworker.out.log
#輸出日志文件
celery_flower.ini
[root@gitlab conf.d]# cat celery_flower.ini
[program:CeleryFlower]
#CeleryFlower 為程序的名稱
command=/root/.envs/hrm/bin/celery flower --address=0.0.0.0 --port=5555
#需要執行的命令
directory=/root/TestProject
#命令執行的目錄
#environment=ASPNETCORE__ENVIRONMENT=Production
#環境變量
user=root
#用戶
stopsignal=INT
autostart=true
#是否自啟動
autorestart=true
#是否自動重啟
startsecs=3
#自動重啟時間間隔(s)
stderr_logfile=/root/TestProject/logs/celeryflower.err.log
#錯誤日志文件
stdout_logfile=/root/TestProject/logs/celeryflower.out.log
#輸出日志文件
supervisorctl 常用命令
supervisorctl # 進入命令控制臺,里面直接敲命令,如:update, start [program]
exit # 退出 supervisorctl 控制臺
supervisorctl reload # 重啟
supervisorctl update # 更新新的配置到 supervisord
supervisorctl status # 查看任務狀態
supervisorctl start [program] # 啟動指定任務,ini 里面 program 的名稱
supervisorctl start all # 啟動全部任務
supervisorctl stop [program] # 停止指定任務
supervisorctl stop all # 停止全部任務
supervisorctl restart [program] # 重啟指定任務
supervisorctl restart all # 重啟全部任務
/usr/bin/python /usr/bin/supervisord -c /etc/supervisord.conf # 啟動 supervisord,centos7 可以配置 systemctl status supervisord.service
ps -ef | grep supervisor # 殺進程,找到進程號后 kill -9 進程號
遇到問題
問題一:unix:///var/run/supervisor/supervisor.sock no such file
解決方案
sudo chmod 777 /run
sudo chmod 777 /var/log
問題二:Unlinking stale socket /var/run/supervisor/supervisor.sock
解決方案
unlink /var/run/supervisor/supervisor.sock
問題三:Error: Another program is already listening on a port that one of our HTTP servers is configured to use. Shut this program down first before starting supervisord.
ps aux | grep supervisord
kill - 9 進程ID
如果還有其他問題可以到你配置的日志目錄下面去查看日志