Newer
Older
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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
#!/bin/bash
cmd=$1
pushd `dirname $0` > /dev/null
scriptdir=`pwd -P`
popd > /dev/null
if [ -z "$CHAOS_TOOLS" ];then
export CHAOS_TOOLS=$scriptdir
fi
source $scriptdir/common_util.sh
# CDS_EXEC=ChaosMetadataService
#CDS_CONF=cds.cfg
MDS_EXEC=mds
UI_EXEC=webui
US_EXEC=UnitServer
AGENT_EXEC=agent
MDS_CONFIG=$CHAOS_PREFIX/etc/localhost/chaosDashboard.json
if [ -z "$CHAOS_PREFIX" ]; then
error_mesg "CHAOS_PREFIX environment variables not set"
exit 1
fi
backend_checks(){
if [ -z "$CHAOS_DB_SERVERS" ];then
if ! ps -fe |grep [m]ongod >/dev/null ;then
error_mesg "mongod not running" ; exit 1
else
ok_mesg "mongod check"
fi
fi
if [ -z "$CHAOS_LIVE_SERVERS" ]; then
if ! ps -fe |grep [e]pmd >/dev/null ;then
if ! ps -fe |grep [m]emcached >/dev/null;then
error_mesg "epmd (couchbase) nor memcached running" ; exit 1
fi
else
ok_mesg "couchbase check"
fi
fi
}
mds_checks(){
MDS_LOG=$CHAOS_PREFIX/log/ChaosMetadataService.log
mkdir -p $CHAOS_PREFIX/log
if [ -x "$CHAOS_PREFIX/bin/$MDS_EXEC" ]; then
MDS_BIN=$CHAOS_PREFIX/bin/$MDS_EXEC
else
error_mesg "$MDS_EXEC binary not found in $CHAOS_PREFIX/bin"
exit 1
fi
}
usage(){
info_mesg "Usage :$0 {start|stop|status| config| start agent| start mds | start webui| start us |start develßdevel | stop webui|stop mds| stop us}"
}
start_mds(){
if [ -n "$CHAOS_MDS" ];then
if ! [[ "$CHAOS_MDS" =~ localhost ]];then
echo "* Using $CHAOS_MDS"
return 1
fi
fi
backend_checks;
mds_checks;
if check_proc "$CHAOS_PREFIX/bin/$MDS_EXEC";then
info_mesg "already running " "MDS.."
else
info_mesg "starting MDS..." "($CHAOS_LIVE_SERVERS)($CHAOS_DB_SERVERS)"
run_proc "$CHAOS_SERVICE_ENV $CHAOS_PREFIX/bin/$MDS_EXEC --conf-file $CHAOS_PREFIX/etc/mds.cfg $CHAOS_OVERALL_OPT $CHAOS_MDS_OPT --log-file $CHAOS_PREFIX/log/$MDS_EXEC.$MYPID.log > $CHAOS_PREFIX/log/$MDS_EXEC.$MYPID.std.out 2>&1 &" "$MDS_EXEC"
# echo "$CHAOS_PREFIX/bin/$MDS_EXEC --conf-file $CHAOS_PREFIX/etc/mds.cfg $CHAOS_OVERALL_OPT $CHAOS_MDS_OPT --log-file $CHAOS_PREFIX/log/$MDS_EXEC.log" >> $CHAOS_PREFIX/log/$MDS_EXEC.std.out
if execute_command_until_ok "grep \"Data Service published\" $CHAOS_PREFIX/log/$MDS_EXEC.$MYPID.log" 120;then
info_mesg "MDS:" " `grep \"Data Service published\" $CHAOS_PREFIX/log/$MDS_EXEC.$MYPID.log`"
sleep 1
ok_mesg "checking publishing"
else
nok_mesg "checking publishing"
return 1
fi
info_mesg "waiting " " 5 seconds"
sleep 5
fi
}
# start_cds(){
# cds_checks
# info_mesg "starting CDS..."
# check_proc_then_kill "$CDS_EXEC"
# echo "$CDS_BIN --conf-file $CHAOS_PREFIX/etc/$CDS_CONF --log-file $CHAOS_PREFIX/log/cds.log" > $CHAOS_PREFIX/log/$CDS_EXEC.std.out
# run_proc "$CDS_BIN --conf-file $CHAOS_PREFIX/etc/$CDS_CONF $CHAOS_OVERALL_OPT --log-file $CHAOS_PREFIX/log/$CDS_EXEC.log >> $CHAOS_PREFIX/log/$CDS_EXEC.std.out 2>&1 &" "$CDS_EXEC"
# }
start_ui(){
if [ -n "$CHAOS_WEBUI" ];then
if ! [[ "$CHAOS_WBUI" =~ localhost ]];then
echo "* Using $CHAOS_WEBUI"
return 1
fi
fi
if check_proc "$CHAOS_PREFIX/bin/$UI_EXEC";then
info_mesg "already running " "webui.."
else
info_mesg "starting " "webui.."
# check_proc_then_kill "$CHAOS_PREFIX/bin/$UI_EXEC"
run_proc "$CHAOS_SERVICE_ENV $CHAOS_PREFIX/bin/$UI_EXEC --conf-file $CHAOS_PREFIX/etc/webui.cfg $port $CHAOS_OVERALL_OPT --log-file $CHAOS_PREFIX/log/webui.$MYPID.log > $CHAOS_PREFIX/log/$UI_EXEC.$MYPID.std.out 2>&1 &" "$UI_EXEC"
fi
# echo "$CHAOS_PREFIX/bin/$UI_EXEC --conf-file $CHAOS_PREFIX/etc/webui.cfg $port $CHAOS_OVERALL_OPT --log-file $CHAOS_PREFIX/log/webui.log" >> $CHAOS_PREFIX/log/$UI_EXEC.std.out
}
start_agent(){
if [ -n "$CHAOS_AGENT" ];then
if ! [[ "$CHAOS_AGENT" =~ localhost ]];then
echo "* Using $CHAOS_AGENT"
return 1
fi
fi
if check_proc "$CHAOS_PREFIX/bin/$AGENT_EXEC";then
info_mesg "already running " "agent.."
else
info_mesg "starting " "agent"
run_proc "$CHAOS_SERVICE_ENV $CHAOS_PREFIX/bin/$AGENT_EXEC --conf-file $CHAOS_PREFIX/etc/agent.cfg $CHAOS_OVERALL_OPT --log-on-file --log-file $CHAOS_PREFIX/log/agent.$MYPID.log > $CHAOS_PREFIX/log/$AGENT_EXEC.$MYPID.std.out 2>&1 &" "$AGENT_EXEC"
fi
}
load_config(){
if [ ! -e "$MDS_CONFIG" ]; then
error_mesg "localhost configuration file not found in \"$MDS_CONFIG\" " "start skipped"
exit 1
fi
info_mesg "transferring configuration to MDS " "$MDS_CONFIG"
if ! jchaosctl --server localhost:8081 --upload $MDS_CONFIG >& $CHAOS_PREFIX/log/jchaosctl.config.std.out ;then
error_mesg "failed initialization of " "MDS with $MDS_CONFIG"
exit 1
fi
}
start_us(){
if check_proc "$CHAOS_PREFIX/bin/$US_EXEC";then
info_mesg "already running " "UnitServer.."
else
if [ ! -e "$CHAOS_PREFIX/etc/cu.cfg" ]; then
warn_mesg "UnitServer configuration file not found in \"$CHAOS_PREFIX/etc/cu.cfg\" " "start skipped"
return
fi
# info_mesg "transferring configuration to MDS " "$CHAOS_PREFIX/etc/localhost/MDSConfig.json"
# if ! run_proc "$CHAOS_PREFIX/bin/ChaosMDSCmd --mds-conf $CHAOS_PREFIX/etc/localhost/MDSConfig.json $CHAOS_OVERALL_OPT -r 1 --log-on-file --log-file $CHAOS_PREFIX/log/ChaosMDSCmd.$MYPID.log > $CHAOS_PREFIX/log/ChaosMDSCmd.$MYPID.std.out 2>&1 " "ChaosMDSCmd";then
# error_mesg "failed initialization of " "MDS"
# exit 1
# fi
sleep 5
info_mesg "starting US through agent " "TEST"
if ! jchaosctl --server localhost:8081 --op start --uid TEST;then
error_mesg "failed starting of " "TEST"
exit 1
fi
# info_mesg "starting " "$US_EXEC"
# run_proc "$CHAOS_PREFIX/bin/$US_EXEC --conf-file $CHAOS_PREFIX/etc/cu.cfg $CHAOS_OVERALL_OPT --log-on-file 1 --log-file $CHAOS_PREFIX/log/$US_EXEC.$MYPID.log > $CHAOS_PREFIX/log/$US_EXEC.$MYPID.std.out 2>&1 &" "$US_EXEC"
fi
}
ui_stop()
{
info_mesg "stopping... " "$UI_EXEC"
stop_proc "$CHAOS_PREFIX/bin/$UI_EXEC"
}
agent_stop()
{
info_mesg "stopping... " "$AGENT_EXEC"
stop_proc "$CHAOS_PREFIX/bin/$AGENT_EXEC"
}
us_stop(){
if check_proc "$CHAOS_PREFIX/bin/$MDS_EXEC" && check_proc "$CHAOS_PREFIX/bin/$UI_EXEC";then
info_mesg "stopping... " "TEST"
if ! jchaosctl --server localhost:8081 --op stop --uid TEST > $CHAOS_PREFIX/log/jchaosctl.stop.std.out ;then
error_mesg "failed stopping of " "TEST"
fi
fi
}
mds_stop()
{
info_mesg "stopping... " "$MDS_EXEC"
stop_proc "$CHAOS_PREFIX/bin/$MDS_EXEC"
}
# cds_stop(){
# info_mesg "stopping CDS..."
# stop_proc "$CDS_EXEC"
# }
start_all(){
local status=0
info_mesg "start all chaos services..."
# start_cds
# status=$((status + $?))
start_mds
status=$((status + $?))
start_ui
status=$((status + $?))
start_agent
status=$((status + $?))
}
stop_all(){
local status=0
info_mesg "stopping all chaos services..."
us_stop
status=$((status + $?))
ui_stop
status=$((status + $?))
mds_stop
status=$((status + $?))
# cds_stop
# status=$((status + $?))
agent_stop
status=$((status + $?))
exit $status
}
status(){
local status=0
check_proc "mongod"
status=$((status + $?))
check_proc "epmd"
status=$((status + $?))
check_proc "$CHAOS_PREFIX/bin/$MDS_EXEC"
status=$((status + $?))
# check_proc "$CDS_EXEC"
# status=$((status + $?))
check_proc "$CHAOS_PREFIX/bin/$UI_EXEC"
status=$((status + $?))
check_proc "$CHAOS_PREFIX/bin/$AGENT_EXEC"
status=$((status + $?))
if [ -n "$(get_pid $CHAOS_PREFIX/bin/$US_EXEC)" ];then
check_proc "$CHAOS_PREFIX/bin/$US_EXEC"
fi
exit $status
}
case "$cmd" in
status)
status
exit 0
;;
config)
load_config
exit 0
;;
start)
if [ -z "$2" ]; then
start_all
else
case "$2" in
mds)
start_mds
exit 0
;;
webui)
start_ui
exit 0
;;
agent)
start_agent
exit 0
;;
us)
start_us
exit 0
;;
devel)
start_mds
start_ui
start_agent
load_config
sleep 1
start_us
exit 0
;;
*)
error_mesg "\"$2\" no such service"
usage
;;
esac
fi
;;
stop)
if [ -z "$2" ]; then
stop_all
else
case "$2" in
mds)
mds_stop
exit 0
;;
us)
us_stop
exit 0
;;
agent)
agent_stop
exit 0
;;
webui)
ui_stop
exit 0
;;
*)
error_mesg "\"$2\" no such service"
usage
;;
esac
fi
;;
*)
usage
exit 1
;;
esac