forked from swaroopch/isbnnetin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
59 lines (43 loc) · 1.86 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
58
59
#!/usr/bin/env python
'''\
Run 'fab --list' to see what commands you can run.
Requires Fabric from www.fabfile.org
'''
import os
import getpass
from fabric.api import env, local, run, sudo
from fabric.context_managers import cd
from fabric.utils import puts
from fabric import colors
env.hosts = ('isbn.net.in:30247',)
LOCAL_DIR = os.getcwd()
REMOTE_DIR = '/home/' + getpass.getuser() + '/web/isbn.net.in/private/isbn.net.in'
def _transfer_files(src, dst, port=22):
'''Sync from local directory to remote directory'''
assert os.getenv('SSH_AUTH_SOCK') is not None # Ensure ssh-agent is running
if not src.endswith('/'):
src = src + '/'
if dst.endswith('/'):
dst = dst[:-1]
local('rsync -avh --delete-before --copy-unsafe-links --exclude "log/*" --exclude ".*.sw*" --exclude "tmp/*" -e "ssh -p {0}" {1} {2}'.format(port, src, dst), capture=False)
def push():
'''Push code to server'''
global LOCAL_DIR, REMOTE_DIR
_transfer_files(LOCAL_DIR, env.host + ':' + REMOTE_DIR, env.port) # transfer the code
with cd(REMOTE_DIR):
#run("env RAILS_ENV=production rake cache:clear") # clear memcache
run("rm -vf public/index.html public/about.html") # remove page caches on disk
run("touch tmp/restart.txt") # restart passenger
try:
sudo("stop isbn.net.in") # stop workers
except:
pass
sudo("cp -v upstart/* /etc/init/") # copy latest upstart files
run("rm -f tmp/pids/delayed_job*") # remove pids
sudo("start isbn.net.in") # start workers
puts(colors.magenta('Success! The {0} server has been updated.'.format(env.host_string)))
def clear_cache():
'''Clear cache on server'''
global REMOTE_DIR
with cd(REMOTE_DIR):
run("rake cache:clear")