【问题标题】:fabric kill gunicorn process only if it is running仅当它正在运行时,织物才会杀死 gunicorn 进程
【发布时间】:2015-10-09 06:17:02
【问题描述】:

我对面料很陌生。在我的织物文件中,我想重新启动 gunicorn。为此,我先杀死 gunicorn 进程,然后再启动它..

看起来像:

def restart_gunicorn():
    run('ps ax|grep gunicorn')
    run('pkill gunicorn')
    run('gunicorn -b 0.0.0.0:8080 %(path)s/application/wsgi &' % env)

当我运行它时,pkill gunicorn 出现错误,因为在开始时我不会运行任何 gunicorn 进程。所以我想检查一下gunicorn进程是否正在运行,然后只杀死gunicorn。如果没有 gunicorn 进程正在运行,我只想启动 gunicorn 进程..

我该怎么做? 需要帮忙。谢谢

【问题讨论】:

标签: python django fabric gunicorn


【解决方案1】:

你可以只添加settings(warn_only=True),只会给你一个警告,但不会执行失败:

def restart_gunicorn():
    run('ps ax|grep gunicorn')
    with settings(warn_only=True):
        run('pkill gunicorn')
    run('gunicorn -b 0.0.0.0:8080 %(path)s/application/wsgi &' % env)

更多关于settings上下文管理器的信息在这里:http://docs.fabfile.org/en/1.10/api/core/context_managers.html#fabric.context_managers.settings

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-14
    • 2020-03-20
    相关资源
    最近更新 更多