-
Notifications
You must be signed in to change notification settings - Fork 2
/
fabfile.py
157 lines (115 loc) · 3.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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#import wingdbstub
import time
import os, sys
#import pexpect
from fabric.api import local, cd, run, env, sudo, require
from gsapi.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']
# TODOs
'''
How to restore to a previous state
Reload uwsgi without sudo
How to kill all uwsgi
pkill uwsgi
'''
# 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/gsapi/:/srv/gs/api/gsapi/venv/lib/python2.7/site-packages/ && nosetests tests')
def hello():
print("Hello world!")
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')
# child = pexpect.spawn(pexpect_params[0])
# child.expect(pexpect_params[1])
# child.sendline(pexpect_params[2])
# child.expect(pexpect_params[3])
# child.sendline(pexpect_params[4])
# child.expect(pexpect_params[5])
# child.sendline(pexpect_params[6])
# child.expect(pexpect_params[7])
# child.sendline(pexpect_params[8])
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')