-
Notifications
You must be signed in to change notification settings - Fork 0
/
stopStart.gradle
227 lines (190 loc) · 6.5 KB
/
stopStart.gradle
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.hidetake:gradle-ssh-plugin:2.7.0'
}
}
apply plugin: 'org.hidetake.ssh'
if (!hasProperty('env')) {
ext.env = System.env['GRADLE_ENV']
}
if (!hasProperty('simultaneouslyShutdownStart')) {
println "Please set simultaneouslyShutdownStart: $simultaneouslyShutdownStart property"
}
println "Building for environment: $env & simultaneouslyShutdownStart: $simultaneouslyShutdownStart"
ssh.settings {
dryRun = false
logging = 'stdout'
timeoutSec = 600000
identity = file("${System.properties['user.home']}/.ssh/id_rsa")
}
remotes {
n1 {
host = '10.0.0.53'
user = 'db'
}
n2 {
host = '10.0.0.63'
user = 'db'
}
n3 {
host = '10.0.0.73'
user = 'db'
}
n4 {
host = '10.0.0.83'
user = 'db'
}
r1 {
host = '10.0.0.51'
user = 'db'
}
r2 {
host = '10.0.0.61'
user = 'db'
}
r3 {
host = '10.0.0.71'
user = 'db'
}
r4 {
host = '10.0.0.81'
user = 'db'
}
sn1 {
host = '10.0.0.54'
user = 'db'
}
sn2 {
host = '10.0.0.64'
user = 'db'
}
sn4 {
host = '10.0.0.84'
user = 'db'
}
sr1 {
host = '10.0.0.52'
user = 'db'
}
sr2 {
host = '10.0.0.62'
user = 'db'
}
sr3 {
host = '10.0.0.72'
user = 'db'
}
}
task stopStartServer {
if (env == 'sandbox') {
if (simultaneouslyShutdownStart.toBoolean()) {
stop(remotes.sn1, "10.0.0.54")
stop(remotes.sr1, "10.0.0.52")
stop(remotes.sn2, "10.0.0.64")
stop(remotes.sr2, "10.0.0.62")
stop(remotes.sn4, "10.0.0.84")
stop(remotes.sr3, "10.0.0.72")
start(remotes.sn1, "10.0.0.54")
startMobile(remotes.sr1, "10.0.0.52")
start(remotes.sn2, "10.0.0.64")
startMobile(remotes.sr2, "10.0.0.62")
start(remotes.sn4, "10.0.0.84")
startMobile(remotes.sr3, "10.0.0.72")
} else {
stopStart(remotes.sn1, "10.0.0.54")
stopStartMobile(remotes.sr1, "10.0.0.52")
stopStart(remotes.sn2, "10.0.0.64")
stopStartMobile(remotes.sr2, "10.0.0.62")
stopStart(remotes.sn4, "10.0.0.84")
stopStartMobile(remotes.sr3, "10.0.0.72")
}
}
if (env == 'prod') {
if (simultaneouslyShutdownStart.toBoolean()) {
stop(remotes.n1, "10.0.0.53")
stop(remotes.r1, "10.0.0.51")
stop(remotes.n2, "10.0.0.63")
stop(remotes.r2, "10.0.0.61")
stop(remotes.n3, "10.0.0.73")
stop(remotes.r3, "10.0.0.71")
stop(remotes.n4, "10.0.0.83")
stop(remotes.r4, "10.0.0.81")
start(remotes.n1, "10.0.0.53")
startMobile(remotes.r1, "10.0.0.51")
start(remotes.n2, "10.0.0.63")
startMobile(remotes.r2, "10.0.0.61")
start(remotes.n3, "10.0.0.73")
startMobile(remotes.r3, "10.0.0.71")
start(remotes.n4, "10.0.0.83")
startMobile(remotes.r4, "10.0.0.81")
} else {
stopStart(remotes.n1, "10.0.0.53")
stopStartMobile(remotes.r1, "10.0.0.51")
stopStart(remotes.n2, "10.0.0.63")
stopStartMobile(remotes.r2, "10.0.0.61")
stopStart(remotes.n3, "10.0.0.73")
stopStartMobile(remotes.r3, "10.0.0.71")
stopStart(remotes.n4, "10.0.0.83")
stopStartMobile(remotes.r4, "10.0.0.81")
}
}
}
def stopStart(def server, def ip) {
logger.lifecycle("--------------------------------------------")
logger.lifecycle("Stop and Start to $server for $env and simultaneouslyShutdownStart = $simultaneouslyShutdownStart")
logger.lifecycle("--------------------------------------------")
sshExecute(server, 'sudo service tomcat stop')
sshExecute(server, 'sleep 20')
sshExecute(server, "sudo service tomcat start")
sshExecute(server, "sleep 35")
sshExecute(server, "sudo service tomcat status")
sshExecute(server, "curl -I http://$ip:8080/open/login")
sshExecute(server, "wget -qO- http://$ip:8080/open/login > /dev/null 2>&1")
}
def stopStartMobile(def server, def ip) {
logger.lifecycle("--------------------------------------------")
logger.lifecycle("Stop and Start to $server for $env and simultaneouslyShutdownStart = $simultaneouslyShutdownStart")
logger.lifecycle("--------------------------------------------")
sshExecute(server, 'sudo service tomcat stop')
sshExecute(server, 'sleep 20')
sshExecute(server, "sudo service tomcat start")
sshExecute(server, "sleep 35")
sshExecute(server, "sudo service tomcat status")
sshExecute(server, "wget -qO- http://$ip:8080/open/healthCheck > /dev/null 2>&1")
}
def stop(def server, def ip) {
logger.lifecycle("--------------------------------------------")
logger.lifecycle("Stop to $server for $env and simultaneouslyShutdownStart = $simultaneouslyShutdownStart")
logger.lifecycle("--------------------------------------------")
sshExecute(server, 'sudo service tomcat stop')
}
def start(def server, def ip) {
logger.lifecycle("--------------------------------------------")
logger.lifecycle("Start to $server for $env and simultaneouslyShutdownStart = $simultaneouslyShutdownStart")
logger.lifecycle("--------------------------------------------")
sshExecute(server, "sudo service tomcat start")
sshExecute(server, "sleep 35")
sshExecute(server, "sudo service tomcat status")
sshExecute(server, "curl -I http://$ip:8080/open/login")
sshExecute(server, "wget -qO- http://$ip:8080/open/login > /dev/null 2>&1")
}
def startMobile(def server, def ip) {
logger.lifecycle("--------------------------------------------")
logger.lifecycle("Start Mobile to $server for $env and simultaneouslyShutdownStart = $simultaneouslyShutdownStart")
logger.lifecycle("--------------------------------------------")
sshExecute(server, "sudo service tomcat start")
sshExecute(server, "sleep 35")
sshExecute(server, "sudo service tomcat status")
sshExecute(server, "wget -qO- http://$ip:8080/open/healthCheck > /dev/null 2>&1")
}
def sshExecute(def server, def cmd) {
logger.lifecycle("Executing '$cmd' ...")
ssh.run {
session(server) {
execute(cmd, pty: false)
}
}
}