Skip to content

Instantly share code, notes, and snippets.

Created Sep 6, 2010
What would you like to do?
from __future__ import with_statement
from fabric.api import *
import urllib2
env.key_filename = ['/home/release/.ssh/sahana_release']
'''Definitions for 'Test' infrastructure'''
def test():
"List of server(s) for test infratructure"
env.user = 'root'
env.hosts = ['']
'''Definitions for 'Production' infrastructure'''
def prod():
"List of server(s) for production infrastructure"
env.user = 'root'
env.hosts = ['']
'''Key distribution and management'''
def generate_keys():
"Generate an SSH key to be used for passwordless control"
local('ssh-keygen -N "" -q -t rsa -f ~/.ssh/sahana_release')
def distribute_keys():
"Distribute keys to servers - requires preceeding test of production"
local('ssh-copy-id -i ~/.ssh/ %s@%s' % (env.user,
'''Deployment, Maintenance and Migrations'''
def deploy():
"Deploy Sahana to servers - requires preceding with test or prod"
def cleanup():
"Cleanup after the bzr pull"
with cd('/home/web2py/applications/eden/'):
run('chown web2py:web2py languages/*', pty=True)
# ToDo: Extend to all conflicts (models at least)
# ToDo: Provide more comforting output (an error here is good!)
run('mv models/ models/', pty=True)
def db_sync():
if not "test" in
# ToDo: Pull database from Live
def maintenance_on():
"Enable maintenance"
# ToDo Disable Cron
run('a2dissite %s' %, pty=True)
run('a2ensite maintenance', pty=True)
def maintenance_off():
"Disable maintenance"
# ToDo Enable Cron
run('a2dissite maintenance', pty=True)
run('a2ensite %s' %, pty=True)
def migrate_on():
"Enabling migrations"
with cd('/home/web2py/applications/eden/models/'):
run('sed -i "s/deployment_settings.base.migrate = False/deployment_settings.base.migrate = True/g"', pty=True)
def migrate():
"Perform a Migration"
#migrate_url = urllib2.urlopen('http://%s/eden/default/index' %
with cd('/home/web2py'):
# ToDo: Pass input into remote PTY
run('sudo -H -u web2py python -S eden -M', pty=True)
def migrate_off():
"Disabling migrations"
with cd('/home/web2py/applications/eden/models/'):
run('sed -i "s/deployment_settings.base.migrate = True/deployment_settings.base.migrate = False/g"', pty=True)
def pull():
"Upgrade the Eden code"
with cd('/home/web2py/applications/eden/'):
# Backup VERSION for rollbacks & so we know which revision Live should pull
# ToDo Parse file instead & make it available for rollback() or the prod pull()
run('cp -f VERSION ..', pty=True)
# ToDo Pass an argument to upgrade to a specific revision
#if env.version:
# run('bzr pull -r %i' % env.version, pty=True)
run('bzr pull', pty=True)
def rollback():
"Rollback from a failed upgrade"
with cd('/home/web2py/applications/eden/'):
# Back-up deployment_settings
run('cp -f models/ ..', pty=True)
# ToDo: Dangerous this will remove all other customisations!
# Need to ensure we list these clearly before doing this!
run('bzr revert -r %i' % env.version, pty=True)
# Restore deployment_settings
run('cp -f ../ models', pty=True)
def reload():
"Reload Apache"
run('apache2ctl restart',pty=True)
def os_upgrade():
"Update OS"
run('apt-get update', pty=True)
run('apt-get upgrade -y', pty=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment