Skip to content

Instantly share code, notes, and snippets.

@jacobh
Created May 3, 2013 07:33
Show Gist options
  • Save jacobh/5507750 to your computer and use it in GitHub Desktop.
Save jacobh/5507750 to your computer and use it in GitHub Desktop.
my base fabfile
from __future__ import with_statement
from fabric.api import *
from fabric.contrib import files
env.roledefs = {
'prod': ['[email protected]'],
'staging': ['[email protected]'],
}
CODE_DIR = '/home/ExampleProject'
PID_FILE = '/tmp/gunicorn_example-project'
GUNICORN_WORKERS = 8
GUNICORN_BIND = '127.0.0.1:8000'
def gunicorn_restart(strength='hard'):
if files.exists(PID_FILE) and strength == 'soft':
run('kill -HUP `cat %s`' % PID_FILE)
else:
with cd(CODE_DIR):
run('bin/gunicorn ExampleProject.wsgi -w %d -p %s -D -b %s' % (
GUNICORN_WORKERS,
PID_FILE,
GUNICORN_BIND
))
def nginx_reload():
run('service nginx reload')
def pull():
with cd(CODE_DIR):
run('git pull')
def pip_update():
with cd(CODE_DIR):
run('bin/pip install -r requirements.txt')
def collect_static():
with cd(CODE_DIR):
run('bin/python manage.py collectstatic --noinput')
def migrate():
with cd(CODE_DIR):
run('bin/python manage.py migrate')
def deploy(level='web'):
execute(pull)
execute(pip_update)
execute(collect_static)
if level == 'all':
execute(migrate)
if level == 'all' or level == 'web':
execute(nginx_reload)
execute(gunicorn_restart, 'soft')
def tail_nginx():
run('tail -f /var/log/nginx/access.log')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment