-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfabfile.py
71 lines (53 loc) · 1.9 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from fabric.colors import green, red
from fabric.contrib.console import confirm
from fabric.api import run, env, cd, put, sudo, abort
# configs
env.user = 'group'
env.hosts = ['210.44.176.241:2722',]
## project home path
PROJECT_HOME = '/home/group/pahchina'
## project name in supervisor
PROJECT_NAME_IN_SUPERVISOR = 'pahchina'
## default deploy branch
DEPLOY_BARNCH = 'zhwei'
def put_sshkey():
"""push ssh key to server
"""
with cd('/tmp'):
put('id_rsa.pub.master', 'id_rsa.pub.master')
run('cat id_rsa.pub.master >> ~/.ssh/authorized_keys')
# git
def git_pull(branch):
ret = run('git pull origin %s' % branch)
if ret.failed and not confirm('Pull from origin %s Failed, Continue anyway ?') % branch:
run('git status')
abort(red('Aborting at pull from origin'))
print(green('Pull from branch %s successfully') % branch)
# service control
def restart_project(project_name):
#if not confirm(green('Do you want to restart project ?')):
sudo('supervisorctl restart %s' % project_name)
print(green('Restart Supervisor project [%s] Successfully !!') % project_name)
def restart_nginx(action="reload"):
sudo('nginx -s %s' % action)
print(green('[%s] Nginx Successfully !!') % action)
# python
def install_require(package=None):
if package:
sudo('pip install %s' % package)
else:
sudo('pip install -r requirements.txt')
print(green('Install Complete !'))
# project custom
def deploy(do='app'):
with cd(PROJECT_HOME):
git_pull(DEPLOY_BARNCH)
install_require()
if 'db' == do:
if not confirm(red("Are you sure to recreate your database ? this can not be undo !!")):
abort('Do Nothing ... ')
run('rm pahchina/db/mysite.db')
run('python manage.py syncdb')
restart_project(PROJECT_NAME_IN_SUPERVISOR)