services: list of tasks to run after deployment
"""
-from fabric.api import *
from os.path import abspath, dirname, exists, join
+from django.utils.crypto import get_random_string
+from fabric.api import *
from fabric.contrib import files
from fabric.tasks import Task, execute
run('mkdir -p %(app_path)s' % env, pty=True)
run('%(virtualenv)s %(app_path)s/ve' % env, pty=True)
- run('mkdir -p %(app_path)s/releases %(app_path)s/packages' % env, pty=True)
+ run('mkdir -p %(app_path)s/releases %(app_path)s/packages %(app_path)s/log' % env, pty=True)
run('cd %(app_path)s/releases; ln -sfT . current; ln -sfT . previous' % env, pty=True)
upload_samples()
print "Fill out db details in localsettings.py and run deploy."
def run(self):
print '>>> restart webserver using gunicorn-debian'
- with path('/sbin'):
- sudo('gunicorn-debian restart %s' % self.site_name, shell=False)
+ sudo('gunicorn-debian restart %s' % self.name, shell=False)
class Apache(Task):
def run(self):
def run(self):
print '>>> supervisord: restart %s' % self.name
- with path('/sbin'):
- sudo('supervisorctl restart %s' % self.name, shell=False)
+ sudo('supervisorctl restart %s' % self.name, shell=False)
def check_setup():
require('app_path')
template = '%(project_name)s/localsettings.py.template'
if not exists(template):
template = join(dirname(abspath(__file__)), 'templates/localsettings.py.template')
- env.secret_key = '' # sth random
+ env.secret_key = get_random_string(50)
files.upload_template(template, '%(app_path)s/localsettings.py.sample' % env, env)
def upload_nginx_sample():
print '>>> symlink current release'
require('release', provided_by=[deploy])
require('app_path')
- with cd(env.path):
+ with cd(env.app_path):
run('rm releases/previous; mv releases/current releases/previous')
run('ln -s %(release)s releases/current' % env)
"Update the database"
print '>>> migrate'
require('app_path', 'project_name')
- with cd('%(app_path)s/releases/current/%(project_name)s' % env):
+ with cd('%(app_path)s/releases/current' % env):
run('%(app_path)s/ve/bin/python manage.py syncdb --noinput' % env, pty=True)
run('%(app_path)s/ve/bin/python manage.py migrate' % env, pty=True)
"""Collect static files"""
print '>>> collectstatic'
require('app_path', 'project_name')
- with cd('%(app_path)s/releases/current/%(project_name)s' % env):
+ with cd('%(app_path)s/releases/current' % env):
run('%(app_path)s/ve/bin/python manage.py collectstatic --noinput' % env, pty=True)