V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
ingin
V2EX  ›  Python

supervisor 管理 gunicorn 进程的问题

  •  
  •   ingin · 2018-11-02 16:05:39 +08:00 · 3457 次点击
    这是一个创建于 1973 天前的主题,其中的信息可能已经有所发展或是发生改变。

    当使用 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 进程呢?

    14 条回复    2018-11-02 18:51:35 +08:00
    xixijun
        1
    xixijun  
       2018-11-02 16:15:56 +08:00
    supervisor 配置加个 killasgroup=true 试试
    gaius
        2
    gaius  
       2018-11-02 16:20:40 +08:00
    手动杀了呗。。
    neoblackcap
        3
    neoblackcap  
       2018-11-02 16:22:12 +08:00
    你的 supervisord 针对 gunicorn 配置了多少个进程?
    我也用过 supervisord 作为 gunicorn 的守护进程,没遇到你的问题
    ingin
        4
    ingin  
    OP
       2018-11-02 16:24:47 +08:00
    @gaius #2 需要使用自动化脚本去更新代码
    ingin
        5
    ingin  
    OP
       2018-11-02 16:25:23 +08:00
    @xixijun #1 好像没作用,谢谢
    ingin
        6
    ingin  
    OP
       2018-11-02 16:26:27 +08:00
    @neoblackcap #3 文中写了 -w4, 您是怎么关闭 gunicorn 进程的呢
    shuax
        7
    shuax  
       2018-11-02 16:28:05 +08:00
    Try using exec gunicorn
    搜了下
    robinlovemaggie
        8
    robinlovemaggie  
       2018-11-02 16:57:38 +08:00
    常识的问一句:为什么要 root 下跑你的程序? python 有用 pyenv 做版本隔离吗?程序依赖有用 venv 隔离吗?有在 dev
    下测试过启动脚本吗?
    xiaowangwang92
        9
    xiaowangwang92  
       2018-11-02 17:26:21 +08:00
    正常情况下是 sudo supervisorctl stop myapp 就可以 kill 掉 gunicorn 进程的,你可以查看下 sudo supervisorctl status 看一下状态。
    ingin
        10
    ingin  
    OP
       2018-11-02 17:58:17 +08:00
    @xiaowangwang92 #9 当 stop myapp 时,状态是 close,但是 gunicorn 进程还在,start myapp 时,状态是 running,然后 gunicorn 进程新增了四个
    xiaowangwang92
        11
    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
        12
    xiaowangwang92  
       2018-11-02 18:30:35 +08:00
    还有就是你说的多出来的 gunicorn 进程是不是你手动起的,忘记关掉了~~~ ^ _ ^ pkill gunicorn
    linnchord
        13
    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
        14
    neoblackcap  
       2018-11-02 18:51:35 +08:00
    @ingin 其实楼下的就说了,你改一下 stopsignal 应该就可以了,而且 gunicorn 不是有 supervisord 的配置范例吗?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5301 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 07:16 · PVG 15:16 · LAX 00:16 · JFK 03:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.