"""
Connection information for the local machine
"""
+ def _custom_local(command):
+ prefixed_command = '/bin/bash -l -i -c "%s"' % command
+ return local(prefixed_command)
+ env.run = _custom_local
# This is required for the same reason as above
- env.proj_dir = os.getcwd()
- env.proj_root = os.path.dirname(env.proj_dir)
+ env.proj_root = '/var/www/karmaworld'
env.cd = lcd
env.reqs = 'reqs/dev.txt'
- env.confs = 'confs/stag/'
+ env.confs = 'confs/beta'
env.branch = 'beta'
- env.run = virtenv_exec
+
+
+####### Define production host
@task
def prod():
"""
Connection Information for production machine
"""
+ env.user = 'djkarma'
+ env.hosts = ['karmanotes.org']
+ env.proj_root = '/var/www/karmaworld'
+ env.reqs = 'reqs/prod.txt'
+ env.confs = 'confs/prod/'
+ env.branch = 'beta'
+ env.run = virtenv_exec
+ env.gunicorn_addr = '127.0.0.1:8000'
+
+####### Define beta host
+@task
+def beta():
+ """
+ Connection Information for beta machine
+ """
+
env.user = 'djkarma'
env.hosts = ['beta.karmanotes.org']
env.proj_root = '/var/www/karmaworld'
- env.proj_dir = '/var/www/karmaworld'
env.reqs = 'reqs/prod.txt'
- env.confs = 'confs/beta/'
+ env.confs = 'confs/prod/'
env.branch = 'beta'
env.run = virtenv_exec
Execute command in Virtualenv
"""
- with virtualenv('%s/%s' % (env.proj_dir, env.branch)):
+ with virtualenv('%s/%s' % (env.proj_root, env.branch)):
run('%s' % (command))
-
-
######## Sync database
@task
def syncdb():
Sync Database
"""
- env.run('%s/manage.py syncdb --noinput --migrate' % env.proj_dir )
+ env.run('%s/manage.py syncdb --migrate' % env.proj_root )
####### Collect Static Files
@task
def collect_static():
"""
- Collect static files (if AWS config. present, push to S3
+ Collect static files (if AWS config. present, push to S3)
"""
- env.run('%s/manage.py collectstatic --noinput' % env.proj_dir )
+ env.run('%s/manage.py collectstatic --noinput' % env.proj_root )
####### Run Dev Server
@task
Runs the built-in django webserver
"""
- env.run('%s/manage.py runserver' % env.proj_dir )
+ env.run('%s/manage.py runserver' % env.proj_root)
####### Create Virtual Environment
@task
Create our Virtualenv in $SRC_ROOT
"""
- run('virtualenv %s/%s' % (env.proj_dir, env.branch))
- env.run('pip install -r %s/reqs/dev.txt' % env.proj_dir )
+ run('virtualenv %s/%s' % (env.proj_root, env.branch))
+ env.run('pip install -r %s/reqs/%s.txt' % (env.proj_root, env.branch) )
-####### Supervisord
@task
def start_supervisord():
- """
- Starts Supervisord
- """
- config_file = '%s/confs/prod/supervisord.conf' % (env.proj_dir)
- env.run('supervisord -c %s' % config_file)
+ """
+ Starts supervisord
+ """
+ config_file = '/var/www/karmaworld/confs/prod/supervisord.conf'
+ env.run('supervisord -c %s' % config_file)
+
@task
def stop_supervisord():
- """
- Stops supervisord
- """
-
- config_file = '%s/confs/prod/supervisord.conf' % (env.proj_dir)
- env.run('supervisorctl -c %s shutdown' % config_file)
+ """
+ Restarts supervisord
+ """
+ config_file = '/var/www/karmaworld/confs/prod/supervisord.conf'
+ env.run('supervisorctl -c %s shutdown' % config_file)
+
@task
def restart_supervisord():
- """
- Restarts supervisord
- """
-
- stop_supervisord()
- start_supervisord()
+ """
+ Restarts supervisord
+ """
+ stop_supervisord()
+ start_supervisord()
+
def supervisorctl(action, process):
- """
- Takes as arguments the name of the process as is
- defined in supervisord.conf and the action that should
- be performed on it: start|stop|restart.
- """
- config_file = '%s/confs/prod/supervisord.conf' % (env.proj_dir)
- env.run('supervisorctl -c %s %s %s' % (config_file, action, process))
+ """
+ Takes as arguments the name of the process as is
+ defined in supervisord.conf and the action that should
+ be performed on it: start|stop|restart.
+ """
+ supervisor_conf = '/var/www/karmaworld/confs/prod/supervisord.conf'
+ env.run('supervisorctl -c %s %s %s' % (supervisor_conf, action, process))
+
@task
def start_celeryd():
"""
supervisorctl('stop', 'celeryd')
+
+@task
+def restart_celery():
+ """
+ Restarts the celeryd process
+ """
+ supervisorctl('restart', 'celeryd')
+
+
@task
def start_gunicorn():
"""
"""
supervisorctl('start', 'gunicorn')
+
@task
def stop_gunicorn():
"""
supervisorctl('restart', 'gunicorn')
+####### Update Requirements
+@task
+def update_reqs():
+ env.run('pip install -r reqs/prod.txt')
+
+####### Pull new code
@task
def update_code():
- env.run('cd %s; git pull' % env.proj_dir)
+ env.run('cd %s; git pull' % env.proj_root )
@task
-def deploy():
+def backup():
"""
- Deploys the latest changes
+ Create backup using bup
"""
- update_code()
+@task
+def first_deploy():
+
+ """
+ Sets up and deploys the project for the first time.
+ """
+ make_virtualenv()
update_reqs()
syncdb()
manage_static()
- restart_supervisord()
+ start_supervisord()
@task
-def User():
- env.run('whoami')
+def deploy():
+ """
+ Deploys the latest changes
+ """
+ update_code()
+ update_reqs()
+ syncdb()
+ collect_static()
+ restart_supervisord()
+########## END COMMANDS