-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
121 lines (105 loc) · 3.29 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
from fabric.colors import green, red
from fabric.contrib.files import exists
from fabric.api import env, cd, run, sudo
from fabric.contrib.project import rsync_project
env.use_ssh_config = True
install_dir = "/apps/returns"
home_dir = "/home/focus"
local_dir = "/home/ekt/go/src/github.com/etowett/"
live_dir = "%s/go/src/github.com/etowett/" % home_dir
user = "focus"
def live():
env.hosts = ["web"]
return
def dev():
env.hosts = ["sms"]
return
def deploy():
with cd("%sreturns" % live_dir):
print(green("Pull changes from bitbucket"))
run("git pull origin master")
print(green("get dependencies if any"))
run("go get")
print(green("build"))
run("go build")
print(green("install new"))
run("go install")
print(red("stop returns application"))
stop_returns()
with cd(install_dir):
if exists("returns"):
print(red("remove old returns"))
run("rm returns")
print(green("copy new returns"))
run("cp %s/go/bin/returns ." % home_dir)
print(green("start returns application"))
restart_returns()
return
def xdeploy():
rsync_project(
live_dir, local_dir='%sreturns' % local_dir,
exclude=['*.pyc', '.git*'], delete=True
)
with cd('%sreturns' % live_dir):
print(green("get dependencies if any"))
run('go get')
print(green("build"))
run('go build')
print(green("install new"))
run('go install')
# print(green("populating redis"))
# run("go run %sreturns/scripts/cache-codes.go" % live_dir)
with cd(install_dir):
if exists("returns"):
print(red("remove old returns"))
run("rm returns")
print(green("copy new returns"))
run("cp /home/focus/go/bin/returns .")
print(green("start service"))
restart_returns()
return
def setup():
sudo("yum -y install go git nginx")
if not exists("/home/focus/go"):
run("mkdir /home/focus/go")
run("echo \"export GOPATH=$HOME/go\" >> /home/focus/.bashrc")
if not exists('%smoniyee' % live_dir):
rsync_project(
live_dir, local_dir='%sreturns' % local_dir,
exclude=['*.pyc', '.git*'], delete=True
)
with cd('%sreturns' % live_dir):
run('go get')
run('go build')
run('go install')
if not exists("/apps"):
sudo("mkdir /apps")
sudo("chown %s:%s /apps" % (user, user,))
with cd("/apps"):
if not exists("returns"):
run("mkdir returns")
with cd("returns"):
run("cp %sreturns/env.sample .env" % (live_dir,))
run("cp /home/focus/go/bin/returns .")
sudo(
"cp %sreturns/config/callbacks.service "
"/etc/systemd/system/callbacks.service" % (live_dir,)
)
sudo(
"cp %sreturns/config/callbacks.conf "
"/etc/nginx/conf.d/" % (live_dir,)
)
with cd("/var/log/"):
if not exists("returns"):
sudo("mkdir returns")
sudo("chown %s:%s returns" % (user, user,))
with cd("returns"):
run("touch returns.log")
restart_returns()
return
def stop_returns():
sudo("systemctl stop callbacks")
return
def restart_returns():
sudo('systemctl restart callbacks')
return