-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
49 lines (35 loc) · 1.92 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
from __future__ import with_statement
import os
from fabric.api import *
env.REMOTE_HOME_PATH = '/home/badger'
env.REMOTE_CODEBASE_PATH = '%s/badger' % env.REMOTE_HOME_PATH
env.PIP_REQUIREMENTS_PATH = 'requirements.txt'
def deploy():
"""
Full git deployment. Migrations, reloading gunicorn.
"""
with settings(host_string='badger.timeho.me', user='root'):
exists = run('if [ -d %s ]; then echo TRUE; fi' % env.REMOTE_CODEBASE_PATH) == 'TRUE'
if not exists:
run('cd %s && git clone git://github.com/timehome/djangodash2012.git badger' % env.REMOTE_HOME_PATH)
else:
run('cd %s && git pull' % env.REMOTE_CODEBASE_PATH)
run('cd %s && pip install -r requirements.txt' % env.REMOTE_CODEBASE_PATH)
run('mkdir -p %s/static' % env.REMOTE_HOME_PATH)
run('cd %s/badger && ./manage.py collectstatic --noinput' % env.REMOTE_CODEBASE_PATH)
restart()
def db():
with settings(host_string='badger.timeho.me', user='root'):
run('mysql -u root --password= -e "DROP DATABASE IF EXISTS badger"')
run('mysql -u root --password= -e "CREATE DATABASE IF NOT EXISTS badger"')
run('cd %s/badger && ./manage.py syncdb' % env.REMOTE_CODEBASE_PATH)
def restart():
with settings(host_string='badger.timeho.me', user='root', warn_only=True):
run("ps aux | egrep gunicorn | egrep -v egrep | awk '{ print $2 }' | xargs kill -9")
run("ps aux | egrep pyres | egrep -v egrep | awk ' { print $2 } ' | xargs kill -9")
#for i in range(2):
#run('/etc/init.d/badger-site-80%02d stop && PYTHONPATH=$PYTHONPATH:%s /etc/init.d/badger-site-80%02d start &' % (i, env.REMOTE_CODEBASE_PATH, i))
#run('WORKERNUM=%d /etc/init.d/pyres-worker start' % i)
run('/etc/init.d/supervisord restart')
run("ps aux | egrep nginx | egrep -v egrep | awk '{ print $2 }' | xargs kill -9")
run('/etc/init.d/nginx restart')