Skip to content

Instantly share code, notes, and snippets.

@mushfiq

mushfiq/fabfile.py

Last active Dec 14, 2015
Embed
What would you like to do?
Fabric boiler plate for deployment.
from fabric.api import local, run, env, put
env.graceful = False
def test_server():
env.user = 'your_user_name'
env.serverpath = '/'
env.site_root = 'your_app_root'
env.password = 'your_pass' #ssh password for user
# env.key_filename = ''# specify server public key
#lis of hossts in env.hosts
env.hosts = [
'test.com',
]
#sample method for git pull
def pull(branch_name):
env.site_root = 'your_project_path'
run('cd %s && git pull origin %s' % (env.site_root, branch_name))
#deploy current directories all code without fabfile.py
def deploy():
env.files = '*'
env.site_name = 'your_app_name'
env.site_path = 'your_application_path'
run('rm -rf %s/%s' % (env.site_path,env.site_name))
local('zip -r %s.zip -x=fabfile.py %s' % (env.site_name, env.files))
put(env.site_name+'.zip',env.site_path)
run('cd %s && unzip %s.zip -d %s && rm %s.zip' % (env.site_root, \
env.site_name, env.site_name, env.site_name))
local('rm -rf %s.zip' % env.site_name)
#restart apache of remote host
def restart_apache():
cmd = "/usr/local/apache2/bin/apachectl -k graceful" if (env.graceful is True) \
else "service httpd restart"
run(cmd)
def latest_access_log():
cmd = "tail -n 10 /var/log/apache2/access.log"
run(cmd)
def latest_error_log():
cmd = "tail -n 10 /var/log/apache2/error.log"
run(cmd)
#!/bin/bash
sudo apt-get install python-pip
sudo pip install fabric
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.