supervisor 管理 gunicorn 进程的问题

2018-11-02 16:05:39 +08:00
 ingin

当使用 supervisor 来管理 gunicorn 的时候,supervisor 配置文件 myapp.conf 中的 command 为:

gunicorn -w4 -b0.0.0.0:8000 run:app 注:这是一个 flask 项目

然后用命令 sudo supervisord -c myapp.conf 启动项目

此时可以查找多条 gunicorn 进程,同时测试接口可用

那么如何关闭这些 gunicorn 进程呢?

实测用 sudo supervisorctl -c myapp.conf stop myapp 命令可以使接口不可访问,但是那些 gunicorn 进程还是存在,当我再次重启 sudo supervisorctl -c myapp.conf start myapp 的时候,进程又多了四个。

我应该如何利用 supervisor 来关闭这些 gunicorn 进程呢?

3480 次点击
所在节点    Python
14 条回复
xixijun
2018-11-02 16:15:56 +08:00
supervisor 配置加个 killasgroup=true 试试
gaius
2018-11-02 16:20:40 +08:00
手动杀了呗。。
neoblackcap
2018-11-02 16:22:12 +08:00
你的 supervisord 针对 gunicorn 配置了多少个进程?
我也用过 supervisord 作为 gunicorn 的守护进程,没遇到你的问题
ingin
2018-11-02 16:24:47 +08:00
@gaius #2 需要使用自动化脚本去更新代码
ingin
2018-11-02 16:25:23 +08:00
@xixijun #1 好像没作用,谢谢
ingin
2018-11-02 16:26:27 +08:00
@neoblackcap #3 文中写了 -w4, 您是怎么关闭 gunicorn 进程的呢
shuax
2018-11-02 16:28:05 +08:00
Try using exec gunicorn
搜了下
robinlovemaggie
2018-11-02 16:57:38 +08:00
常识的问一句:为什么要 root 下跑你的程序? python 有用 pyenv 做版本隔离吗?程序依赖有用 venv 隔离吗?有在 dev
下测试过启动脚本吗?
xiaowangwang92
2018-11-02 17:26:21 +08:00
正常情况下是 sudo supervisorctl stop myapp 就可以 kill 掉 gunicorn 进程的,你可以查看下 sudo supervisorctl status 看一下状态。
ingin
2018-11-02 17:58:17 +08:00
@xiaowangwang92 #9 当 stop myapp 时,状态是 close,但是 gunicorn 进程还在,start myapp 时,状态是 running,然后 gunicorn 进程新增了四个
xiaowangwang92
2018-11-02 18:18:58 +08:00
@ingin 我觉得要么可能是 supervisor 配置的问题,要么是启动方式的问题,参考下这个 https://medium.com/ymedialabs-innovation/deploy-flask-app-with-nginx-using-gunicorn-and-supervisor-d7a93aa07c18
xiaowangwang92
2018-11-02 18:30:35 +08:00
还有就是你说的多出来的 gunicorn 进程是不是你手动起的,忘记关掉了~~~ ^ _ ^ pkill gunicorn
linnchord
2018-11-02 18:38:54 +08:00
```
[program:portal]
directory=/var/www/portal
command=/home/dev/.pyenv/versions/portal/bin/gunicorn --worker-class=gevent --max-requests 5000 -w 6 -b 127.0.0.1:8100 portal:app
loglevel=info
autostart=true
autorestart=true

redirect_stderr=true
stdout_logfile=/var/log/portal.log
user=dev
stopsignal=TERM

stdout_logfile_maxbytes=0
stdout_logfile_backups=0
```

通过 supervisorctl start|stop|restart 控制,启停的关键参数应该是 stopsignal=TERM
neoblackcap
2018-11-02 18:51:35 +08:00
@ingin 其实楼下的就说了,你改一下 stopsignal 应该就可以了,而且 gunicorn 不是有 supervisord 的配置范例吗?

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/503838

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX