2 """ Karmaworld Fabric management script
3 Finals Club (c) 2013"""
7 from fabric.api import cd, env, lcd, prefix, run, task, local, settings
8 from fabvenv import virtualenv
11 env.proj_repo = 'git@github.com:FinalsClub/karmaworld.git'
14 ######## Define host(s)
18 Connection information for the local machine
21 # This is required for the same reason as above
22 env.proj_dir = os.getcwd()
23 env.proj_root = os.path.dirname(env.proj_dir)
25 env.reqs = 'reqs/dev.txt'
26 env.confs = 'confs/stag/'
28 env.run = virtenv_exec
32 ####### Define production host
36 Connection Information for production machine
40 env.hosts = ['karmanotes.org']
41 env.proj_root = '/var/www/karmaworld'
42 env.proj_dir = '/var/www/karmaworld'
43 env.reqs = 'reqs/prod.txt'
44 env.confs = 'confs/beta/'
46 env.run = virtenv_exec
47 env.gunicorn_addr = '127.0.0.1:8000'
49 ####### Define beta host
53 Connection Information for beta machine
57 env.hosts = ['beta.karmanotes.org']
58 env.proj_root = '/var/www/karmaworld'
59 env.proj_dir = '/var/www/karmaworld'
60 env.reqs = 'reqs/beta.txt'
61 env.confs = 'confs/beta/'
63 env.run = virtenv_exec
64 env.gunicorn_addr = '127.0.0.1:8000'
66 ######## Run Commands in Virutal Environment
67 def virtenv_exec(command):
69 Execute command in Virtualenv
72 with virtualenv('%s/%s' % (env.proj_dir, env.branch)):
75 ######## Sync database
82 env.run('%s/manage.py syncdb --noinput --migrate' % env.proj_dir )
85 ####### Collect Static Files
89 Collect static files (if AWS config. present, push to S3
92 env.run('%s/manage.py collectstatic --noinput' % env.proj_dir )
94 ####### Run Dev Server
98 Runs the built-in django webserver
101 env.run('%s/manage.py runserver' % env.proj_dir )
103 ####### Create Virtual Environment
105 def make_virtualenv():
107 Create our Virtualenv in $SRC_ROOT
110 run('virtualenv %s/%s' % (env.proj_root, env.branch))
111 env.run('pip install -r %s/reqs/%s.txt' % (env.proj_dir, env.branch) )
114 def start_supervisord():
118 config_file = '/var/www/karmaworld/confs/prod/supervisord.conf'
119 env.run('supervisord -c %s' % config_file)
123 def stop_supervisord():
127 config_file = '/var/www/karmaworld/confs/prod/supervisord.conf'
128 env.run('supervisorctl -c %s shutdown' % config_file)
132 def restart_supervisord():
140 def supervisorctl(action, process):
142 Takes as arguments the name of the process as is
143 defined in supervisord.conf and the action that should
144 be performed on it: start|stop|restart.
146 supervisor_conf = '/var/www/karmaworld/confs/prod/supervisord.conf'
147 env.run('supervisorctl -c %s %s %s' % (supervisor_conf, action, process))
153 Starts the celeryd process
155 supervisorctl('start', 'celeryd')
161 Stops the celeryd process
163 supervisorctl('stop', 'celeryd')
167 def restart_celery():
169 Restarts the celeryd process
171 supervisorctl('restart', 'celeryd')
175 def start_gunicorn():
177 Starts the gunicorn process
179 supervisorctl('start', 'gunicorn')
185 Stops the gunicorn process
187 supervisorctl('stop', 'gunicorn')
191 def restart_gunicorn():
193 Restarts the gunicorn process
195 supervisorctl('restart', 'gunicorn')
198 ####### Update Requirements
201 env.run('pip install -r reqs/prod.txt')
203 ####### Pull new code
206 env.run('cd %s; git pull' % env.proj_dir)
211 Create backup using bup