forked from anwen/anwen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
91 lines (63 loc) · 1.64 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from fabric.api import *
env.use_ssh_config = True
# env.hosts = ['aw']
# env.user = 'root'
# env.key_filename = '~/.ssh/aw_rsa'
def hello():
print("Hello world!")
def whoami():
run('whoami')
def pwd():
run('pwd')
def host_type():
run('uname -s')
@task
def nginx(todo):
''' nginx:todo= '''
# fab -H aw nginx:todo=start
sudo('/etc/init.d/nginx %s' % todo)
@task
def update_nginx():
''' update_nginx '''
put('/home/ask/anwen/conf/nginx.conf', '/usr/local/nginx/conf/nginx.conf')
sudo('/etc/init.d/nginx reload')
@task
def back_data():
''' backup data from aw mongo '''
with cd('/var/www/anwen/db'): # 切换到远程目录
run('./db_in_out.py -o')
run('tar czf aw_yaml.tar.gz *.yaml') # 远程解压
with cd('/var/www/anwen/docs/shares'):
run('tar czf aw_md.tar.gz *.md') # 远程解压
with lcd('~/anwen/db/'): # 切换到local
get('/var/www/anwen/db/aw_yaml.tar.gz', '.')
local('tar zxf aw_yaml.tar.gz')
with lcd('~/anwen/docs/shares/'):
get('/var/www/anwen/docs/shares/aw_md.tar.gz', '.')
local('tar zxf aw_md.tar.gz')
def test():
local("make test")
def commit():
try:
local("git add -p && git add . && git commit -a")
except:
pass
def push():
local("git push aw_gh")
local("git push prod")
@task
def deploy():
test()
commit()
push()
def deploy_2():
# todo
code_dir = '/home/lb/'
with cd(code_dir):
host_type()
run("git pull")
def print_user():
with hide('running'):
run('echo "%(user)s"' % env)