Skip to content
This repository has been archived by the owner on Jan 28, 2020. It is now read-only.

Commit

Permalink
fabfile template is setup. readme now lists assumptions about deploym…
Browse files Browse the repository at this point in the history
…ent.
  • Loading branch information
jcsackett committed Jul 17, 2009
1 parent 99f87f6 commit 71c1b69
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
This project is highly geared towards my usage right now. As such it makes certain assumptions.

1) You will deploy along the same directory structure on every server.
2) You will have set up every server with the same username for administration
3) You will be using lighty as a proxy to handle static media and pass off to apache for django
4) You will be using mod_wsgi
5) You have three servers: one for internal usage, one for staging, and one for external production usage
6) You will apache and lighttpd both setup with user/group of www-data
111 changes: 111 additions & 0 deletions templates/fabfile.py.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
config.fab_hosts = [{{staging}}, {{production}}, {{internal}}]

def internal():
config.fab_hosts = [{{internal}}]
config.db_user = {{internal_db_user}}
config.db_password = {internal_db_password}}
config.conf = 'internal'

def staging():
config.fab_hosts = [{{staging}}]
config.db_user = {{staging_db_user}}
config.db_password = {{staging_db_password}}
config.conf = 'staging'

def production():
config.fab_hosts = [{{production}}]
config.db_user = {{production_db_user}}
config.db_password = {{production_db_password}}
config.conf = 'production'

def init():
#create the database
run('echo "create database {{db}};" | mysql --user=$(db_user) --password=$(db_password)')

#create the folders
put('scripts/setup_directories.sh', 'setup_directories.sh')
run('chmod +x setup_directories.sh')
run('./setup_directories.sh && rm setup_directories.sh')

#checkout the code
run('cd /home/websites/{{project}}/ && {{repo_cmd}} {{repo}} {{code}}')

#create syslinks
put('scripts/setup_syslinks.sh', 'setup_syslinks.sh')
run('chmod +x setup_syslinks.sh')
run('./setup_syslinks.sh && rm setup_syslinks.sh')

#push up conf files
put('conf/$(conf)/99-{{project}}.conf', '99-{{project}}.conf')
put('conf/$(conf)/{{project}}', '{{project}}')
sudo('mv 99-{{project}}.conf /etc/lighttpd/conf-available && mv {{project}} /etc/apache2/sites-available')

#push up local settings and start setting up database
put('conf/$(conf)/settings_local.py', 'settings_local.py')
run('mv settings_local.py /home/websites/{{project}}/{{code}}')
run('cd /home/websites/{{project}}/{{code}} && python manage.py syncdb --noinput')

#enable config files
sudo('a2ensite {{project}}')
sudo('lighty-enable-mod {{project}}')
force_permissions()

print 'Remember if you\'ve deployed to production, you need to manually link admin_media into the lighttpd site media folder.'
print 'Remember you need to call the restart operation to start the server once everything is initialized.'

def force_permissions():
#cover our butts, permissions wise
sudo('chown -R www-data:www-data /home/websites/{{project}}')
sudo('chown -R www-data:www-data /home/websites/lighttpd/{{project}}')
sudo('chmod -R 775 /home/websites/{{project}}')
sudo('chmod -R 775 /home/websites/lighttpd/{{project}}')

def update():
run('cd /home/websites/{{project}}/{{code}} && svn up')
run('cd /home/websites/{{project}}/{{code}} && python manage.py syncdb --noinput')
print "Please note you need to execute a 'restart' command before your code changes will work."

def db_kill():
#TODO: Make sure this cannot run without db-backup being set
run('echo "drop database {{db}};" | mysql --user=$(db_user) --password=$(db_password)')

def db_backup():
run('mysqldump --user=$(db_user) --password=$(db_password) {{db}} > ~/{{db}}.sql')
run('gzip {{db}}.sql')
download('{{db}}.sql.gz', '{{db}}_backup.sql.gz', fail='abort')
#TODO: Setup backup successful flag

def db_restore():
pass

def site_kill():
#TODO: Require backup flag
sudo('rm -rf /home/websites/{{project}}')
sudo('rm -rf /home/websites/lighttpd/{{project}}')
sudo('a2dissite {{project}}')
sudo('lighty-disable-mod {{project}}')
sudo('rm /etc/apache2/sites-available/{{project}}')
sudo('rm /etc/lighttpd/conf-available/99-{{project}}.conf')


def site_backup():
"""Downloads a tarball of the site to the fabric user."""
run("cd /home/websites/ && tar -cvf ~/{{project}}.tar {{project}}")
run("gzip {{project}}.tar")
download('{{project}}.tar.gz', '${{project}}_backup.tar.gz', fail='abort')
#TODO: Setup backup successful flag

def site_restore():
pass

def offline():
"""Replaces the site with a static "Site is down for maintenance" page."""
raise NotImplemented('This is on the wishlist.')

def online():
"""Brings the site back after offline() is called."""
raise NotImplemented('This is on the wishlist.')

def restart():
sudo('/etc/init.d/apache2 restart')
sudo('/etc/init.d/lighttpd restart')
6 changes: 5 additions & 1 deletion templates/settings.py.tmpl
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
PROJECT_HOME = '' #the name of the directory the project will be hosted under
PROJECT = ''
#PROJECT_HOME = '' #the name of the directory the project will be hosted under
PROJECT_HOME = PROJECT
CODE_HOME = '' #the name of the directory the code will be hosted in

REPO_TYPE = '' #one of git, hg, or svn
REPO = '' #the url of the code repo
USER = '' #The user for the server
MYSQL_DB = PROJECT
#MYSQL_DB = '' #the name of the database

#SERVER BASED SETUP INFO
# Each of the following variables consists of a three part tuple, defining
Expand Down

0 comments on commit 71c1b69

Please sign in to comment.