-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfabfile.py
executable file
·77 lines (57 loc) · 2.01 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date : 2016-03-14 15:58:57
# @Author : Linsir (root@linsir.org)
# @Link : http://linsir.org
# OpenResty module fabric scripts for developers.
import os
# from fabric.api import local,cd,run,env,put
from fabric.colors import *
from fabric.api import *
prefix = '/usr/local/openresty'
M_PATH = 'lib/resty/ipip'
APP_NAME = "demo"
PORT = "8000"
import paramiko
paramiko.util.log_to_file('/tmp/paramiko.log')
# 2. using sshd_config
env.hosts = [
'master',# master
]
env.use_ssh_config = True
def install():
run('sudo opm install pintsized/lua-resty-http')
def local_update():
print(yellow("copy %s and configure..." %APP_NAME ))
local("sudo cp -r %s %s/site/lualib/resty" %(M_PATH, prefix))
if os.path.exists("%s/%s/" %(prefix, APP_NAME)):
local("sudo rm -rf %s/%s/" %(prefix, APP_NAME))
local("sudo cp -r %s %s" %(APP_NAME, prefix))
if os.path.exists("%s/nginx/conf/conf.d/%s.conf" %(prefix, APP_NAME)):
local("sudo rm -rf %s/nginx/conf/conf.d/%s.conf" %(prefix, APP_NAME))
local("sudo ln -s %s/%s/%s.conf %s/nginx/conf/conf.d/%s.conf" %(prefix, APP_NAME, APP_NAME, prefix, APP_NAME))
reload()
local('curl 127.0.0.1:%s/' %PORT)
def remote_update():
print(yellow("copy %s and configure..." %APP_NAME))
run('sudo rm -rf %s/%s/' %(prefix, APP_NAME))
put(APP_NAME, '%s/')
put("%s/", "%s/site/site/lualib/resty" %(M_PATH, prefix))
with cd('%s/nginx/conf/conf.d/' %prefix):
if not os.path.exists("%s/nginx/conf/conf.d/%s.conf" %(prefix, APP_NAME)):
run('sudo ln -s %s/%s/%s.conf %s.conf' %(APP_NAME, APP_NAME, APP_NAME))
reload()
def reload():
print(green("nginx reload..."))
local('sudo openresty -t && sudo openresty -s reload')
def restart():
print(green("nginx restarting..."))
local('sudo systemctl restart openresty')
def update():
# local update
local_update()
# remote update
# remote_update()
pass
if __name__ == '__main__':
pass