天天看點

Python程式設計:使用supervisor管理Django-Celery程序安裝配置啟動

supervisor 程序管理工具

安裝

python

2

pip install supervisor      

配置

$ mkdir config

# 生成配置檔案
$ echo_supervisord_conf > config/supervisord.conf      

修改配置檔案 config/supervisord.conf

1、開啟web管理界面:inet_http_server

2、開啟管理:supervisorctl.serverurl

3、開啟配置檔案:include

[include]
files = *.ini      

建立日志 logs檔案夾

配置3個程序管理檔案

1、supervisor_celery_worker.ini

[program:celery-worker]
command=python manage.py celery worker -l INFO
directory=celery_learn/celery_project
environment=PATH="/.virtualenvs/py3/bin"
stdout_logfile=celery_learn/celery_project/logs/celery.worker.log
stderr_logfile=celery_learn/celery_project/logs/celery.worker.log
autostart=true
autorestart=true
startsecs=10
stopwaitsecs=60
priority=998
      

2、supervisor_celery_beat.ini

[program:celery-worker]
command=python manage.py celery beat -l INFO
directory=celery_learn/celery_project
environment=PATH="/.virtualenvs/py3/bin"
stdout_logfile=celery_learn/celery_project/logs/celery.beat.log
stderr_logfile=celery_learn/celery_project/logs/celery.beat.log
autostart=true
autorestart=true
startsecs=10
stopwaitsecs=60
priority=997
      

3、supervisor_celery_flower.ini

[program:celery-worker]
command=python manage.py celery flower
directory=celery_learn/celery_project
environment=PATH="/.virtualenvs/py3/bin"
stdout_logfile=celery_learn/celery_project/logs/celery.flower.log
stderr_logfile=celery_learn/celery_project/logs/celery.flower.log
autostart=true
autorestart=true
startsecs=10
stopwaitsecs=60
priority=996
      

啟動

supervisord -c config/supervisord.conf      

管理工具

> supervisorctl
> help
> update   # 更新配置檔案      

管理界面

http://127.0.0.1:9001/

配置參數參考:

http://www.supervisord.org/configuration.html#program-x-section-settings