Restart Gunicorn_django via Fabric

你。 提交于 2019-12-11 20:33:31

问题


I'm building a Django application and I decided to investigate Fabric for automating deployment. I've got it mostly working, but it fails at the last step, and I can't seem to puzzle out why.

I'm using Nginx and Gunicorn to serve the application, and I want to kill and restart Gunicorn after the changes have been pulled in and the database updated. Unfortunately it always seems to fail at the last hurdle.

The final command doesn't respond with any kind of error, but the application isn't getting served, and if I SSH in there's no process for it and I have to restart it manually. Every other command works perfectly.

My fabfile.py:

#!/usr/bin/env python
from fabric.api import local, env, run
from fabric.context_managers import cd, prefix

env.hosts = ['192.168.1.1']
env.path = "/home/matthew/Sites/projectname"


def deploy():
    # Push changes to Bitbucket
    local('git push origin master')

    # Switch to project directory
    with cd(env.path):
        # Pull changes to server
        run('git pull origin master')

        # Activate virtualenv
        with prefix('source venv/bin/activate'):

            # Collect static files
            run('python manage.py collectstatic --noinput')

            # Sync and migrate the database
            run('python manage.py syncdb')
            run('python manage.py migrate')

            # Kill and restart Gunicorn
            run('killall gunicorn_django || true')
            run('gunicorn_django -D -c gunicorn.conf.py')

If I drop the -D flag so it isn't daemonised, it works and I get the following output, but I have to disconnect manually with Ctrl-C. If I append & to the end, that stops it working:

[192.168.1.1] out: 2013-05-22 12:47:51 [60549] [INFO] Starting gunicorn 0.17.4
[192.168.1.1] out: 2013-05-22 12:47:51 [60549] [INFO] Listening at: http://127.0.0.1:8888 (60549)
[192.168.1.1] out: 2013-05-22 12:47:51 [60549] [INFO] Using worker: sync
[192.168.1.1] out: 2013-05-22 12:47:51 [60554] [INFO] Booting worker with pid: 60554
[192.168.1.1] out: 2013-05-22 12:47:51 [60555] [INFO] Booting worker with pid: 60555
[192.168.1.1] out: 2013-05-22 12:47:51 [60556] [INFO] Booting worker with pid: 60556
[192.168.1.1] out: 

Can anyone see where I've gone astray?


回答1:


Didn't ever resolve this as such, but I finally knuckled down and picked up Supervisor. As it turned out, Supervisor was pretty simple to use and thanks to this blog post I was able to puzzle it out quite quickly. Just thought I'd post this in case someone else has the same kind of issue and stumbles across this page.




回答2:


I was facing this issue too. I waited for few seconds between killing and restarting the gunicorn process and it seems to run fine for now.

kill_running_gunicorn_process()
time.sleep(10)
start_gunicorn_process()


来源:https://stackoverflow.com/questions/16689873/restart-gunicorn-django-via-fabric

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!