Created
May 3, 2013 07:33
-
-
Save jacobh/5507750 to your computer and use it in GitHub Desktop.
my base fabfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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