-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
134 lines (95 loc) · 3.33 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import time
import os, sys
from fabric.api import local, cd, run, env, sudo, require
from exi.local_settings import Config
fab = Config.FABRIC['live']
env.hosts = fab['HOSTS']
env.user = fab['ADMIN_USER']
env.admin_ = fab['ADMIN_USER']
env.admin_user = fab['ADMIN_USER']
env.password = fab['ADMIN_PW']
# def deploy(push_code=False):
def deploy(msg="No Msg"):
#if push_code:
#commit_code()
commit(msg)
update_remote()
run_tests()
reload_uwsgi()
def commit(msg):
with cd(os.path.abspath(os.path.dirname(__file__))):
local('git add .')
local('git commit -am"%s"' % msg)
local('git push origin master') # push local to repository
def update_remote():
env.user = fab['WEB_USER']
with cd(fab['PROJECT_ROOT']):
run('git pull origin master') # pull from repository to remote
# def run_tests():
# with cd(fab['PROJECT_ROOT']):
# run('export PYTHONPATH=/srv/gs/api/pyfem/:/srv/gs/api/pyfem/venv/lib/python2.7/site-packages/ && nosetests tests')
# def r():
# # symlink convenience
# # ln -s /home/flt/django/projects/flt/ /home/flt/dj
# run('cd C:\Users\Larry\__prjs\flt; ls')
#from fabric.decorators import runs_once
from fabric.contrib.console import confirm
# see: http://blog.tplus1.com/index.php/2010/12/31/how-to-restart-a-gunicorn-server-from-vim/
def reload_code():
with cd(fab['PROJECT_ROOT']):
sudo('kill -HUP `cat gunicorn.pid`')
def start_gunicorn():
with cd(fab['PROJECT_ROOT']):
sudo('python manage.py run_gunicorn -c gunicorn.conf.py --traceback 0.0.0.0:8001')
def stop_gunicorn():
with cd(fab['PROJECT_ROOT']):
sudo('kill `cat gunicorn.pid`')
def restart_gunicorn():
with cd(fab['PROJECT_ROOT']):
sudo('kill `cat gunicorn.pid`')
sudo('python manage.py run_gunicorn -c gunicorn.conf.py --traceback 0.0.0.0:8001')
def reload_uwsgi():
sudo('pkill -9 uwsgi')
def reload_uwsgi():
with cd(fab['PROJECT_ROOT']):
run('pkill -9 uwsgi')
def reload_nginx_conf():
sudo('/etc/init.d/nginx check')
sudo('/etc/init.d/nginx reload')
def restart():
sudo('supervisorctl restart ourfield')
# sudo /etc/init.d/nginx restart
sudo('/etc/init.d/nginx restart')
def pushpull():
local('git push') # runs the command on the local environment
run('cd /path/to/project/; git pull') # runs the command on the remote environment
# the following is fab file from another project
# from fabric.api import run, env, cd, sudo
# def production():
# env.hosts = ['yourhost.com']
# env.repo = ('/srv/yourproject/', 'origin', 'master')
# def git_pull(hash=None):
# """Updates or resets the repository"""
# repo, parent, branch = env.repo
# if hash is None:
# hash = '%s/%s' % (parent, branch)
# with cd(repo):
# run('git fetch')
# run('git reset --hard %s' % hash)
# def buildout():
# repo, parent, branch = env.repo
# with cd(repo):
# run('./bin/buildout')
# def deploy(hash=None):
# repo, parent, branch = env.repo
# git_pull(hash)
# buildout()
# with cd(repo):
# run('./bin/django syncdb')
# restart_supervisor()
# def reset(hash):
# deploy(hash)
# def restart_nginx():
# sudo('/etc/init.d/nginx restart')
# def restart_supervisor():
# sudo('supervisorctl restart all')