djangonginxreloadgunicornupstart

A better way to restart/reload Gunicorn (via Upstart) after 'git pull'ing my Django projects


Im looking for something better than sudo restart projectname every time I issue a git pull origin master, which pulls down my latest changes to a Django project. This restart command, I believe, is related to Upstart, which I use to start/top my Gunicorn server process.

This restart causes a brief outage. Users hitting the web server (nginx) will get a 500, because Gunicorn is still restarting. In fact, it seems to restart instantly, but it takes a few seconds for pages to load.

Any ideas on how to make this seamless? Ideally, I'd like to issue my git pull and Gunicorn reloads automatically.


Solution

  • For a graceful reload, you should instead use Upstart's reload command, e.g.:

    sudo reload jobname
    

    According to the initctl (Upstart) manpage, reload will send a HUP signal to the process:

    reload JOB [KEY=VALUE]...
    
           Sends the SIGHUP signal to running process of the named JOB instance.
    

    ...which for Gunicorn will trigger a graceful restart (see FAQ).