Gunicorn Simple Release Script
March 31, 2011
Here's a simple script, making use of http://drumcoder.co.uk/blog/2011/mar/31/sudo-restart-gunicorn/, which will upload the latest source, run a django syncdb
, then a south migrate
, and then finally send a HUP
signal to gunicorn.
To scripts are required, upload and restart. Here's the upload script:
SRC_DIR=~/path/to/django/app/ DEST_DIR=user@server.co.uk:path/to/django/app EXCLUDES=~/path/to/django/app/upload_excludes.txt RSYNC_OPTS="-avz --exclude-from=$EXCLUDES" rsync $RSYNC_OPTS $SRC_DIR $DEST_DIR ssh user@server.co.uk "cd /path/to/django/app;./restart"
Here's the restart script, making use of sudo without a password:
#!/bin/bash cd ./django_app ./manage.py syncdb --settings=settingslive ./manage.py migrate --settings=settingslive PID=`sudo -u server_user cat /tmp/gunicorn.pid` sudo -u server_user /bin/kill -HUP $PID