This script is intended to help people who develop applications using Gunicorn by automatically sending an HUP signal to the master process when python files are changed.
Please note that this script only works on a Linux OS, mainly because it uses pyinotify
Simplest example:
./gunicorn_hup_on_change.py
Will restart the first gunicorn master process it finds, and will watch for modifications in the current python path.
If you want to watch specific directories, you can use the following:
./gunicorn_hup_on_change.py ./lib/ ./ext/lib/
You can also target a specific gunicorn process using -a
, in case
you have multiple gunicorn instances running:
./gunicorn_hup_on_change.py -a my_app
Will search for a process "named" gunicorn: master [my_app]
You can also pass a pidfile that is storing the master gunicorn pid using -p
, if
that option is specified when gunicorn is started:
./gunicorn_hup_on_change.py -p /tmp/my_app.pid
Will simply open and read that file for the pid.
By default, the watcher will wait 500ms after a file's modification to send the
HUP signal, to avoid sending multiple signals when you update a batch of files
(when updating your repository for example).
You can change this interval with the -w
option