-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdateCode
More file actions
executable file
·309 lines (291 loc) · 10.9 KB
/
Copy pathupdateCode
File metadata and controls
executable file
·309 lines (291 loc) · 10.9 KB
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
#!/bin/bash
#
# updateCode - utility to update FutureGateway code on a given machine
#
# Author: Riccardo Bruno <riccardo.bruno@ct.infn.it>
#
HASSUDO=0 # 1 - In case futuregateway has a passwordless sudoer account
FRONTENDSESSIONNAME=fgAPIServer
FGUSER=futuregateway
COPYFROM=
COPYTO=
UPLOADTO=
UPDATEALL=0
APISERVERDAEMON_HOME=$HOME/Documents/APIServerDaemon
APISERVERFRONTEND_HOME=$HOME/Documents/fgapiserver
TOSCAADAPTOR_GIT="https://github.com/csgf/jsaga-adaptor-tosca"
TOSCAADAPTOR_HOME=$HOME/Documents/jsaga-adaptor-tosca
ROCCIADAPTOR_GIT="https://github.com/csgf/jsaga-adaptor-rocci"
ROCCIADAPTOR_HOME=$HOME/Documents/jsaga-adaptor-rocci
FGAPISERVER_GIT=https://github.com/FutureGateway/fgAPIServer.git
APISERVERDAEMON_GIT=https://github.com/FutureGateway/APIServerDaemon.git
ts() {
date +%Y%m%d%H%M%S
}
out() {
TS=$(ts)
echo "$TS $*"
}
err() {
TS=$(ts)
echo "$TS $*" >&2
}
show_usage() {
cat <<EOF
usage: updateCode -h <ip|host> # FutureGateway host
[-p <ssh port>] (default 22) # FutureGateway ssh port
[-c <fgAPIServer # code: APIServer front-end
|APIServerDaemon # code: APIServerDaemon
|jsaga-adaptor-rocci> # code: rOCCI adaptor
|jsaga-adaptor-tosca>] # code: tosca adaptor
[ -f <file/directory path> # Upload Local file/dir
[-t <destination dir> ]] # \$FGLOCATION/<file/dir>
[-u <file/directory path>] # Download file/dir from remote
[-a] # Update all components
[-s] # Start futuregateway service
This script copies the specified source package into specified remote host
using ssh connection, for this reason it is recommended to exchange the
ssh keys between source and destination hosts
By default the script stops the futuregateway service leaving it not running
unless the the option -s is specified
EOF
exit 1
}
remote_exec_run() {
OUT=$(mktemp)
ssh -q -p $SSH_PORT $FGUSER@$SSH_HOST "source ~/.bash_profile ; $*" >$OUT 2>/dev/null
dos2unix $OUT >/dev/null 2>/dev/null
cat $OUT
rm -f $OUT
}
remote_exec() {
OUT=$(mktemp)
ERR=$(mktemp)
ssh -q -p $SSH_PORT $FGUSER@$SSH_HOST "source ~/.bash_profile ; $*" >$OUT 2>$ERR
dos2unix $OUT >/dev/null 2>/dev/null
while read ln; do
out "$ln"
done < $OUT
dos2unix $ERR >/dev/null 2>/dev/null
while read ln; do
err "$ln"
done < $ERR
rm -f $OUT
rm -f $ERR
}
local_exec() {
OUT=$(mktemp)
ERR=$(mktemp)
$* >$OUT 2>$ERR
while read ln; do
out "$ln"
done < $OUT
while read ln; do
err "$ln"
done < $ERR
rm -f $OUT
rm -f $ERR
}
parse_options() {
out "Parsing options and validating connection"
SSH_HOST=
SSH_PORT=22
STARTFGSERVER=0
while getopts "h:p:c:sf:t:u:a" opt >/dev/null 2>/dev/null
do
case $opt in
h)
SSH_HOST=$OPTARG
;;
p)
SSH_PORT=$OPTARG
;;
c)
CODE=$OPTARG
;;
s)
STARTFGSERVER=1
;;
a)
UPDATEALL=1
;;
f)
COPYFROM=$OPTARG
;;
t)
COPYTO=$OPTARG
;;
u)
UPLOADTO=$OPTARG
;;
*)
err "Unable to parse options correctly"
show_usage
return 1
esac
done
if [ "$SSH_HOST" != "" -a \
"$CODE" != "" -o \
"$COPYFROM" != "" -o \
"$UPLOADTO" != "" -o \
"$UPDATEALL" -ne 0 \
]; then
out "SSH_HOST : '"$SSH_HOST"'"
out "SSH_PORT : '"$SSH_PORT"'"
out "CODE : '"$CODE"'"
FGLOCATION=$(remote_exec_run "echo \$FGLOCATION")
if [ "$FGLOCATION" = "" ]; then
err "It seems the specified host does not host a FutureGateway environment"
return 1
fi
out "FGLOCATION: '"$FGLOCATION"'"
else
err "One of the mandatory parameters is missing"
show_usage
return 1
fi
out "Successfully connected to futuregateway remote host"
return 0
}
futuregateway_service() {
if [ $HASSUDO -ne 0 ]; then
remote_exec "sudo service futuregateway $1"
else
case $1 in
'start')
remote_exec "\
screen -dmS $FRONTENDSESSIONNAME bash; sleep 5;\
screen -S $FRONTENDSESSIONNAME -X stuff \"cd $FGLOCATION/fgAPIServer; ./fgapiserver.py\n\""
CATALINA_HOME=$(remote_exec_run "echo \$CATALINA_HOME")
remote_exec "\
source ~/.bash_profile;\
source /lib/lsb/init-functions;\
start_daemon $CATALINA_HOME/bin/startup.sh"
;;
'stop')
remote_exec "screen -X -S $FRONTENDSESSIONNAME quit;"
remote_exec "stop_tomcat; sleep 1; killjava"
;;
*)
err "Unsupported futuregateway service command: $1"
esac
fi
}
update_fgAPIServer() {
REBUILD=$1
TS=$(ts)
if [ "$REBUILD" = "" ]; then
out "Updating APIServer front-end"
# First make a backup of existing code in remote machine
remote_exec "cd \$FGLOCATION/fgAPIServer/ && tar cvfz ${TS}_fgapisrv.tar.gz *.py *.sql *.conf *.wsgi && rm -rf *.py *.pyc *.sql *.conf *.wsgi"
local_exec "scp -r -p -P$SSH_PORT $APISERVERFRONTEND_HOME/*.py $FGUSER@$SSH_HOST:$FGLOCATION/fgAPIServer/"
local_exec "scp -r -p -P$SSH_PORT $APISERVERFRONTEND_HOME/*.sql $FGUSER@$SSH_HOST:$FGLOCATION/fgAPIServer/"
local_exec "scp -r -p -P$SSH_PORT $APISERVERFRONTEND_HOME/*.conf $FGUSER@$SSH_HOST:$FGLOCATION/fgAPIServer/"
local_exec "scp -r -p -P$SSH_PORT $APISERVERFRONTEND_HOME/*.wsgi $FGUSER@$SSH_HOST:$FGLOCATION/fgAPIServer/"
else
out "Renewing APIServer front-end"
remote_exec "mv \$FGLOCATION/fgAPIServer \$FGLOCATION/${TS}_fgAPIServer"
remote_exec "cd $FGLOCATION && git clone $FGAPISERVER_GIT"
remote_exec "rm -rf \$FGLOCATION/fgAPIServer/apps && cp -r \$FGLOCATION/${TS}_fgAPIServer/apps \$FGLOCATION/fgAPIServer/"
fi
}
update_APIServerDaemon() {
REBUILD=$1
TS=$(ts)
if [ "$REBUILD" = "" ]; then
out "Updating APIServer daemon"
# First make a backup of existing code in remote machine
remote_exec "cd \$FGLOCATION/APIServerDaemon/ && tar cvfz ${TS}_src.tar.gz src/ && rm -rf src"
local_exec "scp -r -p -P$SSH_PORT $APISERVERDAEMON_HOME/src $FGUSER@$SSH_HOST:$FGLOCATION/APIServerDaemon/"
local_exec "scp -r -p -P$SSH_PORT $APISERVERDAEMON_HOME/web/WEB-INF/log4j.properties $FGUSER@$SSH_HOST:$FGLOCATION/APIServerDaemon//web/WEB-INF/"
local_exec "scp -r -p -P$SSH_PORT $APISERVERDAEMON_HOME/web/WEB-INF/web.xml $FGUSER@$SSH_HOST:$FGLOCATION/APIServerDaemon//web/WEB-INF/"
local_exec "scp -r -p -P$SSH_PORT $APISERVERDAEMON_HOME/web/WEB-INF/classes/it/infn/ct/APIServerDaemon.properties $FGUSER@$SSH_HOST:$FGLOCATION/APIServerDaemon/web/WEB-INF/classes/it/infn/ct/"
local_exec "scp -r -p -P$SSH_PORT $APISERVERDAEMON_HOME/web/WEB-INF/classes/it/infn/ct/GridEngineLogConfig.xml $FGUSER@$SSH_HOST:$FGLOCATION/APIServerDaemon/web/WEB-INF/classes/it/infn/ct/"
else
out "Renewing APIServer daemon"
remote_exec "mv \$FGLOCATION/APIServerDaemon \$FGLOCATION/${TS}_APIServerDaemon"
remote_exec "cd $FGLOCATION && git clone $APISERVERDAEMON_GIT && cp -r \$FGLOCATION/${TS}_APIServerDaemon/web/WEB-INF/lib \$FGLOCATION/APIServerDaemon/web/WEB-INF"
fi
remote_exec "cd \$FGLOCATION/APIServerDaemon/ && ant all && cp \$FGLOCATION/APIServerDaemon/dist/APIServerDaemon.war \$CATALINA_HOME/webapps"
}
update_adaptor-tosca() {
REBUILD=$1
TS=$(ts)
if [ "$REBUILD" = "" ]; then
out "Updating tosca adaptor"
else
out "Renewing tosca adaptor"
remote_exec "[ -d \$FGLOCATION/jsaga-adaptor-tosca ] && mv \$FGLOCATION/jsaga-adaptor-tosca \$FGLOCATION/${TS}_jsaga-adaptor-tosca"
fi
remote_exec "[ ! -d \$FGLOCATION/jsaga-adaptor-tosca ] && cd $FGLOCATION && git clone $TOSCAADAPTOR_GIT && mv $FGLOCATION/jsaga-adaptor-tosca/build.xml $FGLOCATION/jsaga-adaptor-tosca/build.xml_nb && mv $FGLOCATION/jsaga-adaptor-tosca/build.xml_disabled $FGLOCATION/jsaga-adaptor-tosca/build.xml"
remote_exec "cd \$FGLOCATION/jsaga-adaptor-tosca/src/it/infn/ct/jsaga/adaptor/ && tar cfvz ${TS}_tosca.tar.gz tosca/ && rm -rf tosca"
local_exec "scp -r -p -P$SSH_PORT $TOSCAADAPTOR_HOME/src/it/infn/ct/jsaga/adaptor/tosca $FGUSER@$SSH_HOST:$FGLOCATION/jsaga-adaptor-tosca/src/it/infn/ct/jsaga/adaptor/"
remote_exec "cd \$FGLOCATION/jsaga-adaptor-tosca && ant all && cp \$FGLOCATION/jsaga-adaptor-tosca/dist/jsaga-adaptor-tosca.jar \$FGLOCATION/APIServerDaemon/web/WEB-INF/lib && cp \$FGLOCATION/jsaga-adaptor-tosca/dist/jsaga-adaptor-tosca.jar \$FGLOCATION/jsaga-1.1.2/lib"
remote_exec "cd \$FGLOCATION/APIServerDaemon/ && ant all && cp \$FGLOCATION/APIServerDaemon/dist/APIServerDaemon.war \$CATALINA_HOME/webapps"
}
update_adaptor-rocci() {
REBUILD=$1
TS=$(ts)
if [ "$REBUILD" = "" ]; then
out "Updating tosca adaptor"
else
out "Renewing rocci adaptor"
remote_exec "[ -d \$FGLOCATION/jsaga-adaptor-rocci ] && mv \$FGLOCATION/jsaga-adaptor-rocci \$FGLOCATION/${TS}_jsaga-adaptor-rocci"
fi
remote_exec "[ ! -d \$FGLOCATION/jsaga-adaptor-rocci ] && cd $FGLOCATION && git clone $ROCCIADAPTOR_GIT"
remote_exec "cd \$FGLOCATION/jsaga-adaptor-rocci/src/it/infn/ct/jsaga/adaptor/ && tar cfvz ${TS}_rocci.tar.gz rocci/ && rm -rf rocci"
local_exec "scp -r -p -P$SSH_PORT $ROCCIADAPTOR_HOME/src/it/infn/ct/jsaga/adaptor/rocci $FGUSER@$SSH_HOST:$FGLOCATION/jsaga-adaptor-rocci/src/it/infn/ct/jsaga/adaptor/"
remote_exec "cd \$FGLOCATION/jsaga-adaptor-rocci && ant all && cp \$FGLOCATION/jsaga-adaptor-rocci/dist/jsaga-adaptor-rocci.jar \$FGLOCATION/APIServerDaemon/web/WEB-INF/lib && cp \$FGLOCATION/jsaga-adaptor-rocci/dist/jsaga-adaptor-rocci.jar \$FGLOCATION/jsaga-1.1.2/lib"
remote_exec "cd \$FGLOCATION/APIServerDaemon/ && ant all && cp \$FGLOCATION/APIServerDaemon/dist/APIServerDaemon.war \$CATALINA_HOME/webapps"
}
update_code() {
if [ "$CODE" != "" ]; then
out "Stopping futuregateway service"
futuregateway_service stop
case $CODE in
"fgAPIServer")
update_fgAPIServer
;;
"APIServerDaemon")
update_APIServerDaemon
;;
"jsaga-adaptor-tosca")
update_adaptor-tosca
;;
"jsaga-adaptor-rocci")
update_adaptor-rocci
;;
*)
err "Unsupported code '"$CODE"'"
esac
elif [ $UPDATEALL -ne 0 ]; then
out "Updating all FutureGateway components"
update_adaptor-tosca 1
update_adaptor-rocci 1
update_APIServerDaemon 1
update_fgAPIServer 1
else
out "No code specified"
fi
if [ $STARTFGSERVER -ne 0 ]; then
out "Starting futuregateway service"
futuregateway_service start
fi
if [ "$COPYFROM" != "" ]; then
out "Copying '"$COPYFROM"' to '"$FGLOCATION"/"$COPYTO"'"
local_exec "scp -r -p -P$SSH_PORT $COPYFROM $FGUSER@$SSH_HOST:$FGLOCATION/$COPYTO"
fi
if [ "$UPLOADTO" != "" ]; then
out "Uploading '"$FGLOCATION/$UPLOADTO"' to '"$(pwd)/$UPLOADTO"'"
local_exec "scp -r -p -P$SSH_PORT $COPYFROM $FGUSER@$SSH_HOST:$FGLOCATION/$UPLOADTO ."
fi
}
successfully_accomplished() {
out "Operation successfully accomplished"
}
#
# updateCode
#
parse_options $* && \
update_code && \
successfully_accomplished