gunicorn+supervisor+conda部署flask

2019-08-07  本文已影响0人  蕴重Liu

基于conda配置环境

--复制后台环境
conda create --name ai-gather --clone ctfs
--激活环境
source activate ai-gather
--在指定环境安装gunicorn,部分包(如tensorflow)可能会不成功,具体可百度
conda install gunicorn

基于supervisor配置文件

安装命令:sudo apt-get install supervisor
本文跳过安装,从配置文件开始

superviosr通过任务描述文件来设置被监管的程序,一般该文件都放置在/etc/supervisor/conf.d路径下面

vi ai-gather.conf

[program:ai-gather]
command=/root/anaconda3/envs/ai-gather/bin/gunicorn -k gevent -w 10 -b 0.0.0.0:6668 gateway_gather:app
directory=/ChainDevOps/lyq/AiVideoServiceEngine/src               ; directory to cwd to before exec (def no cwd)

stopsignal=INT               ; signal used to kill process (default TERM)

stdout_logfile=/data/log/supervisor/ai-gather.out.log   ; stderr log path, NONE for none; default AUTO
stdout_logfile_maxbytes=4GB   ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=10     ; # of stdout logfile backups (default 10)

stdout_events_enabled=true   ; emit events on stdout writes (default false)

stderr_logfile=/data/log/supervisor/ai-gather.err.log   ; stderr log path, NONE for none; default AUTO
stderr_logfile_maxbytes=1GB   ; max # logfile bytes b4 rotation (default 50MB)
stderr_logfile_backups=10     ; # of stderr logfile backups (default 10)

stderr_events_enabled=true   ; emit events on stderr writes (default false)

启动服务

root@ubuntu:~ # supervisorctl ai-gather
*** Unknown syntax: ai-gather
root@ubuntu:~ # supervisorctl reread
ai-gather: available
root@ubuntu:~ # supervisorctl update
ai-gather: added process group
root@ubuntu:~ # supervisorctl status ai-gather
ai-gather                        RUNNING   pid 18880, uptime 0:00:12
root@ubuntu:~ # supervisorctl stop ai-gather
ai-gather: stopped
root@ubuntu:~ # supervisorctl status ai-gather
ai-gather                        STOPPED   Aug 07 02:29 PM
root@ubuntu:~ # supervisorctl start ai-gather
ai-gather: started
root@ubuntu:~ # supervisorctl status ai-gather
ai-gather                        RUNNING   pid 20123, uptime 0:00:04
--启动app失败,显示ERROR (abnormal termination),使用以下命令查看错误信息
root@ubuntu:~ # supervisorctl tail ai-gather

root@ubuntu:~ # 

设置进程不随着supervisor的启动而启动,尤其适用于资源紧张的情况

autostart = false     ; 若为true,在 supervisord 启动的时候也自动启动
autorestart = false   ; 若为true,程序异常退出后自动重启
上一篇 下一篇

猜你喜欢

热点阅读