Created
May 11, 2014 16:50
-
-
Save akshar-raaj/b100af21ca807298c0fd to your computer and use it in GitHub Desktop.
Minimal fabfile
This file contains 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 fabric.api import run, env, cd | |
from fabric.colors import green | |
from fabric.context_managers import prefix | |
import time | |
env.hosts = ['<your_ip>'] | |
env.user = '<user_on_server>' | |
def pull_code(): | |
print(green('Pulling code')) | |
run('git pull') | |
print(green('Pulled code')) | |
def install_requirements(): | |
print(green('Installing requirements')) | |
run('pip install -r requirements.txt') | |
print(green('Installed requirements')) | |
def kill_gunicorn_process(): | |
print(green('Killing gunicorn')) | |
run('kill -9 `cat gunicorn.pid`') | |
print(green('Killed gunicorn')) | |
def start_gunicorn_process(): | |
print(green('Starting gunicorn')) | |
run('gunicorn web_application:application -c gunicorn_cfg.py', pty=False) | |
print(green('Started gunicorn')) | |
def restart_nginx(): | |
print(green('Starting nginx')) | |
run('sudo service nginx restart') | |
print(green('Started nginx')) | |
def deploy(): | |
code_dir = '~/fabric/fabric-workshop/' | |
with(cd(code_dir)): | |
with(prefix('source ~/fabric/bin/activate')): | |
pull_code() | |
install_requirements() | |
kill_gunicorn_process() | |
time.sleep(10) | |
start_gunicorn_process() | |
restart_nginx() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment