0

I am very new to fabric. In my fabric file I want to restart gunicorn. For that I am killing the gunicorn process first and then starting it..

It looks like:

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

When I run this it gives me error at pkill gunicorn because at start i will not have any gunicorn process running. So I want to have a check lik if gunicorn processes are running then only kill gunicorn. If not gunicorn process are running I just want to start the gunicorn process..

How can I do this ? Need help. Thank you

1

1 Answer 1

0

You can just add settings(warn_only=True) and will only give you a warning, but the execution won't fail:

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)

More info on settings context manager here: http://docs.fabfile.org/en/1.10/api/core/context_managers.html#fabric.context_managers.settings

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.