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.
If you update your Django application, you can restart the Gunicorn process to pick up the changes by typing: sudo systemctl restart gunicorn.
If you are running gunicorn on a port rather than a socket, you can find the process id (pid) of gunicorn using fuser command. Then force gunicorn to reload the code by sending a HUP signal. The command fuser 8000/tcp will list the process ids of all processes using tcp port 8000.
You can tell Gunicorn to reload gracefully using the HUP
signal like so:
kill -HUP <pid>
(see the FAQ for details)
I use Supervisor to control my Gunicorn server, which allows me to use this (slightly hacky) way of reloading Gunicorn after a deploy:
supervisorctl status gunicorn | sed "s/.*[pid ]\([0-9]\+\)\,.*/\1/" | xargs kill -HUP
You could obviously achieve something similar with pidof
, or ps
.
This is actually run from a Fabric script, so I don't even have to logon to the server at all.
For those not using supervisord: what Rob said, it works with ps as well,
ps aux |grep gunicorn |grep projectname | awk '{ print $2 }' |xargs kill -HUP
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With