Skip to content

Instantly share code, notes, and snippets.

@erny
Created October 30, 2013 19:15
Show Gist options
  • Save erny/7238421 to your computer and use it in GitHub Desktop.
Save erny/7238421 to your computer and use it in GitHub Desktop.
Make gunicorn reload during code changes for development, based on http://stackoverflow.com/a/19502993/308351 . Pre-alpha script.
#!/bin/bash
PIDFILE=gunicorn.pid
EXTENSIONS="*.py;*.html;*.css;*.js"
APP=wsgiapp:application
WORKERS=3
function runserver() {
echo "Starting gunicorn"
PYTHONPATH=.:bin gunicorn $APP -w $WORKERS --pid $PIDFILE -D
echo "gunicorn started with PID $!"
if [ "$?" != "0" ]
then
echo "Startup error"
exit 1
fi
}
function observe_and_reload() {
sleep 1
echo "Observing sources..."
watchmedo shell-command -p "$EXTENSIONS" -R --command "kill -s SIGHUP `cat $PIDFILE`" .
}
function stopserver() {
echo "Killing gunicorn"
kill -s SIGTERM `cat $PIDFILE`
}
runserver
observe_and_reload
stopserver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment