-
Notifications
You must be signed in to change notification settings - Fork 17
/
fabfile.py
57 lines (48 loc) · 1.53 KB
/
fabfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from fabric.api import *
from fabric.utils import abort
from fabric.contrib.project import rsync_project
from fabric.contrib.files import exists
if not env.hosts:
env.hosts = ['[email protected]']
project_name = 'stackphp.com'
target_dir = '/var/www/'+project_name
backup_dir = target_dir+'-backup'
staging_dir = target_dir+'-staging'
@task(default=True)
def deploy():
puts('> Cleaning up previous backup and staging dir')
run('rm -rf %s %s' % (backup_dir, staging_dir))
puts('> Preparing staging')
run('cp -r %s %s' % (target_dir, staging_dir))
puts('> Uploading changes')
with cd(staging_dir):
with hide('stdout'):
extra_opts = '--omit-dir-times'
rsync_project(
env.cwd,
'./',
delete=True,
exclude=['.git', '*.pyc'],
extra_opts=extra_opts,
)
puts('> Switching changes to live')
run('mv %s %s' % (target_dir, backup_dir))
run('mv %s %s' % (staging_dir, target_dir))
@task
def rollback():
if exists(backup_dir):
puts('> Rolling back to previous deploy')
run('mv %s %s' % (target_dir, staging_dir))
run('mv %s %s' % (backup_dir, target_dir))
else:
abort('Rollback failed, no backup exists')
@task
def reload():
puts('> Reloading nginx and php5-fpm')
run('service nginx reload')
run('service php5-fpm reload')
@task
def restart():
puts('> Restarting nginx and php5-fpm')
run('service nginx restart')
run('service php5-fpm restart')