美文网首页
gunicorn+supervisor+conda部署flask

gunicorn+supervisor+conda部署flask

作者: 蕴重Liu | 来源:发表于2019-08-07 14:53 被阅读0次

基于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)
  • command:启动命令,使用conda:ai-gather环境的gunicorn启动项目,项目的启动py是 gateway_gather(gateway_gather.py,大多数是manage.py),-w 线程数,-b 端口,可不设置
  • directory:项目启动文件的所在目录路径
  • stdout_logfile: 一个服务一个专用的启动日志文件,注意需提前创建文件夹
  • stdout_logfile_maxbytes:日志轮转切割,不解释
  • stderr_logfile: 一个服务一个专用的启动日志报错文件,注意需提前创建文件夹

启动服务

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,程序异常退出后自动重启

相关文章

网友评论

      本文标题:gunicorn+supervisor+conda部署flask

      本文链接:https://www.haomeiwen.com/subject/qomodctx.html