最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】supervisor调用gunicorn去运行Flask的app没反应

app crifan 4868浏览 0评论

折腾:

【已解决】Flask的gunicorn的启动任务管理supervisor

期间,对于之前用命令行的gunicorn:

gunicorn -w 4 -b 0.0.0.0:21084 run:app &

使用如下配置:

[run:app]
command=/root/Envs/RunningFast/bin/    gunicorn -w 4 -b 0.0.0.0:21084 run:app &
directory=/root/RunningFast
startsecs=0
stopwaitsecs=0
autostart=false
autorestart=false
stdout_logfile=/root/RunningFast/logs/gunicorn.log
stderr_logfile=/root/RunningFast/logs/gunicorn.err

如图:

但是结果好像没有输出:

然后去试试:

好像没啥输出啊:

(RunningFast) ➜  RunningFast supervisord -c supervisor.conf
(RunningFast) ➜  RunningFast supervisorctl -c supervisor.conf status
(RunningFast) ➜  RunningFast supervisorctl -c supervisor.conf reload
Restarted supervisord 

没有之前单独运行gunicorn的flask的输出

1.怀疑是:

对了-》是把输出都log到log文件了??

结果发现也没有gunicorn的log啊:

(RunningFast) ➜  RunningFast ll logs                   
total 4.0K
-rw-r–r– 1 root root 840 Sep 29 16:44 RunningFast.log

2.随便折腾了下,也还是不行:

(RunningFast) ➜  RunningFast supervisorctl -c supervisor.conf stop
Error: stop requires a process name
stop <name>             Stop a process
stop <gname>:*          Stop all processes in a group
stop <name> <name>      Stop multiple processes or groups
stop all                Stop all processes
(RunningFast) ➜  RunningFast supervisorctl -c supervisor.conf start app
app: ERROR (no such process)
(RunningFast) ➜  RunningFast supervisorctl -c supervisor.conf start runningfast
runningfast: ERROR (no such process)
(RunningFast) ➜  RunningFast supervisorctl -c supervisor.conf start all   

3.此处是参考某人,把command放在前面,directory放在后面了:

去参考:

记录flask + gunicorn + supervisor 的配置

“# 注意要让directory放在前面,至少我一开始因为这个原因一直没有成功运行”

所以打算去换个位置。

4.还没来得及换位置,就刚发现,之前的配置写错了:

gunicorn前面多了个空格:

command=/root/Envs/RunningFast/bin/ gunicorn -w 4 -b 0.0.0.0:21084 run:app &

应该是:

command=/root/Envs/RunningFast/bin/gunicorn -w 4 -b 0.0.0.0:21084 run:app &

所以,再去试试:

好像还是不行:

(RunningFast) ➜  RunningFast supervisord -c supervisor.conf 
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.
For help, use /root/Envs/RunningFast/bin/supervisord -h
(RunningFast) ➜  RunningFast supervisorctl -c supervisor.conf reload
Restarted supervisord
(RunningFast) ➜  RunningFast supervisorctl -c supervisor.conf start app
app: ERROR (no such process)

5.然后还是去把位置换了:

directory=/root/RunningFast
command=/root/Envs/RunningFast/bin/gunicorn -w 4 -b 0.0.0.0:21084 run:app &

再去试试,还是不行,status还是无输出:

supervisorctl -c supervisor.conf status

6.去看官网,内容太多,懒得看:

Introduction — Supervisor 3.3.1 documentation

7.搜:

supervisorctl status 无输出

使用 supervisor 管理进程 – 李林克斯

发现了:

之前配置写错了:

[run:app]

应该改为:

[program:runningfast]

果然就可以了:

(RunningFast) ➜  RunningFast supervisorctl -c supervisor.conf reload   
Restarted supervisord
(RunningFast) ➜  RunningFast supervisorctl -c supervisor.conf start runningfast
runningfast: started
(RunningFast) ➜  RunningFast supervisorctl -c supervisor.conf status           
runningfast                      RUNNING   pid 2238, uptime 0:00:11
(RunningFast) ➜  RunningFast ll logs/  
total 8.0K
-rw-r–r– 1 root root 500 Sep 29 21:19 gunicorn.err
-rw-r–r– 1 root root   0 Sep 29 21:19 gunicorn.log
-rw-r–r– 1 root root 840 Sep 29 16:44 RunningFast.log

可以看到有log文件了。

且status也有正常输出了。

也去试了试restart:

(RunningFast) ➜  RunningFast supervisorctl -c supervisor.conf restart runningfast  
runningfast: stopped
runningfast: started

【总结】

此处supervisor不工作,是自己连续犯了多个错误:

1.不小心把gunicorn命令路径多加了个空格:

command=/root/Envs/RunningFast/bin/    gunicorn -w 4 -b 0.0.0.0:21084 run:app &

去掉即可:

command=/root/Envs/RunningFast/bin/gunicorn -w 4 -b 0.0.0.0:21084 run:app &

2.好像是最好是:

把directory参数放在command之前,比较好

-》估计其实也没影响,具体没去验证。

3.此处不小心把配置写错了:

[run:app]

改为:

[program:runningfast]

即可。

转载请注明:在路上 » 【已解决】supervisor调用gunicorn去运行Flask的app没反应

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.179 seconds, using 22.18MB memory