Django使用supervisor管理celery和uwsgi实践记录 uwsgi BACKOFF Exited too quickly (process log may have details)

Django使用supervisor管理celery和uwsgi实践记录

安装下载supervisor不用多说。

直接上配置文件:
vir_path标识虚拟环境路径
pro_path标识项目路径
全部都是绝对路径

[program:uwsgi]
command=/vir_path/uwsgi --ini /pro_path/hs_uwsgi.ini
directory=/pro_path
autostart=true
autorestart=true
stdout_logfile=/pro_path/deploy/ss_uwsgi_access.log
stderr_logfile=/pro_path/deploy/ss_uwsgi_error.log

[program:celery]
command=/vir_path/bin/celery worker -A celery_tasks -l info
directory=/pro_path
stdout_logfile=/pro_path/deploy/ss_celery_access.log
stderr_logfile=/pro_path/deploy/ss_celery_error.log
autorestart=true
redirect_stderr=true

执行supservirctl控制台命令

supervisorctl
celery                           RUNNING   pid 4102, uptime 0:04:03
uwsgi                            RUNNING   pid 26404, uptime 0:00:00
supervisor> reload
Really restart the remote supervisord process y/N? y
Restarted supervisord
supervisor> status
celery                           RUNNING   pid 27971, uptime 0:00:03
uwsgi                            BACKOFF   Exited too quickly (process log may have details)

看到celery正常执行,uwsgi却执行失败,错误信息:
uwsgi BACKOFF Exited too quickly (process log may have details)

原因暂未查明!
上网查阅资料,决定重写配置文件:

[program:uwsgi]
command=/vir_path/uwsgi --ini /pro_path/hs_uwsgi.ini
directory=/pro_path
# 开始等待时间
startsecs=0
# 停止等待时间
stopwaitsecs=0
autostart=true
autorestart=true
stdout_logfile=/pro_path/deploy/ss_uwsgi_access.log
stderr_logfile=/pro_path/deploy/ss_uwsgi_error.log

[program:celery]
command=/vir_path/bin/celery worker -A celery_tasks -l info
directory=/pro_path
# 开始等待时间
startsecs=0
# 停止等待时间
stopwaitsecs=0
autorestart=true
redirect_stderr=true
stdout_logfile=/pro_path/deploy/ss_celery_access.log
stderr_logfile=/pro_path/deploy/ss_celery_error.log

调换了一下日志位置,且加入开始等待时间和停止等带时间

编辑完成之后重启服务:

ubuntu:/etc/supervisor/conf.d$ sudo supervisorctl reload
Restarted supervisord
ubuntu:/etc/supervisor/conf.d$ sudo supervisorctl
celery                           RUNNING   pid 1140, uptime 0:00:02
uwsgi                            RUNNING   pid 1440, uptime 0:00:00

发现可以了

补充一个问题:
在supervisor控制台使用stop命令:

supervisor> stop uwsgi
uwsgi: stopped
supervisor> stop uwsgi
uwsgi: ERROR (not running)

显示是使用一次stop即可,但是查看uwsgi的进程数,发现只比开启时少了1个,网上说是stop命令只是杀死了父进程,对于子进程没有进行控制,尝试加入下列参数:

# 设置为守护进程
daemon=true

重新加载并且重启服务,再次使用stop发现所有与项目相关的uwsgi进程全部被杀死。

完成。

你可能感兴趣的:(supervisor)