A great tool is envdir
apt-get install envdir
mkdir /etc/mysite.d/env
echo "postgres://postgres:@localhost:5432/mysite" > /etc/mysite.d/env/DATABASE_URL
echo "s3ce3t K3Y" > /etc/mysite.d/env/SECRET_KEY
echo "/srv/www/mysite/static" > /etc/mysite.d/env/STATIC_ROOT
echo "mysite.settings" > /etc/mysite.d/env/DJANGO_SETTINGS_MODULE
etc. etc. for all variables to set. Then prefix all commands with envdir /etc/mysite.d/env
. If you have a site deployed in a virtualenv located in /srv/www/mysite/venv
, here is how to run gunicorn to serve this site:
envdir /etc/mysite.d/env /srv/www/mysite/venv/bin/gunicorn mysite.wsgi
And to run a management command:
envdir /etc/mysite.d/env /srv/www/mysite/venv/bin/python manage.py migrate --list
It's a bit of typing for cron entries and initscripts / supervisor scripts but works very well.