forked from leo-project/leofs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mdcr.sh
executable file
·348 lines (292 loc) · 8.57 KB
/
mdcr.sh
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
#!/bin/sh
#-------------------------------------------------------------------------------
# GLOBALS
#-------------------------------------------------------------------------------
NCLUSTERS=2
CLUSTER_NSTORAGES=4
#-------------------------------------------------------------------------------
# ROUTINES
#-------------------------------------------------------------------------------
usage()
{
echo "usage: $0 [help|-h|--help]" >&2
echo " $0 <command> [<args>]" >&2
echo "" >&2
echo "Commands:" >&2
echo "" >&2
echo " help Display usage" >&2
echo " clean Clean environment" >&2
echo " deploy Build and deploy environment" >&2
echo " start [<cl> [<node>]] Start nodes" >&2
echo " status [<cl> [<node>]] Show status" >&2
echo " stop [<cl> [<node>]] Stop nodes" >&2
echo " ping [<cl> [<node>]] Ping nodes" >&2
echo " adm [<cl> [args]] Run leofs-adm" >&2
echo " rmsh <cl> <node> Run remote shell on node" >&2
echo "" >&2
echo "Examples:" >&2
echo "" >&2
echo " ./mdcr.sh deploy" >&2
echo " ./mdcr.sh start" >&2
echo " ./mdcr.sh ping" >&2
echo " ./mdcr.sh adm c1 start" >&2
echo " ./mdcr.sh adm c2 start" >&2
echo " ./mdcr.sh adm c1 status" >&2
echo " ./mdcr.sh adm c1 join-cluster \\" >&2
echo " [email protected]:13095 \\" >&2
echo " [email protected]:13096" >&2
echo " ./mdcr.sh adm c1 cluster-status" >&2
echo " ./mdcr.sh ping c1 manager_0" >&2
echo " ./mdcr.sh rmsh c1 manager_1" >&2
echo "" >&2
exit 1
}
#-------------------------------------------------------------------------------
validate_cluster_name()
{
local name=$1 ; shift
case "${name}" in
c[0-9])
;;
*)
echo "invalid cluster name: ${name}" >&2
exit 1
;;
esac
}
#-------------------------------------------------------------------------------
cluster_name()
{
local id=$1 ; shift
echo "c$((id + 1))"
}
#-------------------------------------------------------------------------------
cluster_id()
{
local name=$1 ; shift
echo "$((${name#c} - 1))"
}
#-------------------------------------------------------------------------------
clean()
{
echo "Cleaning..."
rm -rf package/leo_*
rm -rf package/c*/leo_*
echo "Cleaned."
}
#-------------------------------------------------------------------------------
deploy()
{
local i j cname
clean
echo "Deploying mdcr..."
make release_for_test
for i in `seq 0 $((NCLUSTERS - 1))`
do
cname=`cluster_name ${i}`
mkdir -p package/${cname}
cp -r package/leo_manager_* package/${cname}
cp -r package/leo_gateway package/${cname}/leo_gateway_0
for j in `seq 0 $((CLUSTER_NSTORAGES - 1))`
do
cp -r package/leo_storage package/${cname}/leo_storage_${j}
done
cp priv/test/mdcr-test/${cname}/leo_manager.conf.0 \
package/${cname}/leo_manager_0/etc/leo_manager.conf
cp priv/test/mdcr-test/${cname}/leo_manager.conf.1 \
package/${cname}/leo_manager_1/etc/leo_manager.conf
cp priv/test/mdcr-test/${cname}/leo_gateway.conf \
package/${cname}/leo_gateway_0/etc/leo_gateway.conf
for j in `seq 0 $((CLUSTER_NSTORAGES - 1))`
do
cp priv/test/mdcr-test/${cname}/leo_storage_${j}.conf \
package/${cname}/leo_storage_${j}/etc/leo_storage.conf
done
sed -i.orig -e 's/^\({intAgentUDPPort,\).*$/\1 4'${i}'20}./' \
package/${cname}/leo_manager_0/snmp/snmpa_manager_0/agent/conf/agent.conf
sed -i.orig -e 's/^\({intAgentUDPPort,\).*$/\1 4'${i}'21}./' \
package/${cname}/leo_manager_1/snmp/snmpa_manager_1/agent/conf/agent.conf
for j in `seq 0 $((CLUSTER_NSTORAGES - 1))`
do
sed -i.orig -e 's/^\({intAgentUDPPort,\).*$/\1 4'${i}'1'${j}'}./' \
package/${cname}/leo_storage_${j}/snmp/snmpa_storage_${j}/agent/conf/agent.conf
done
sed -i.orig -e 's/^\({intAgentUDPPort,\).*$/\1 4'${i}'00}./' \
package/${cname}/leo_gateway_0/snmp/snmpa_gateway_0/agent/conf/agent.conf
done
rm -rf package/leo_manager_*
rm -rf package/leo_storage
rm -rf package/leo_gateway
echo "Deployed."
}
#-------------------------------------------------------------------------------
rc()
{
local cmd clusters nodes
# ugly hack for ubuntu
if [ "$#" -ne "0" ]
then
cmd="$1"; shift
fi
if [ "$#" -ne "0" ]
then
clusters="$1"; shift
fi
if [ "$#" -ne "0" ]
then
nodes="$1"; shift
fi
local i c n rc status
if [ -z "${clusters}" ]
then
for i in `seq 0 $((NCLUSTERS - 1))`
do
clusters="${clusters} $(cluster_name ${i})"
done
else
for c in ${clusters}
do
validate_cluster_name "${c}"
done
fi
status=0
for c in ${clusters}
do
validate_cluster_name "${c}"
if [ -z "${nodes}" ]
then
nodes="manager_0 manager_1"
for i in `seq 0 $((CLUSTER_NSTORAGES - 1))`
do
nodes="${nodes} storage_${i}"
done
nodes="${nodes} gateway_0"
fi
for n in ${nodes}
do
rc="./package/${c}/leo_${n}/bin/leo_${n%_[0-9]}"
if [ ! -x "${rc}" ]
then
echo "can't find rc script (${rc}) for cluster/node ${c}/${n}" >&2
exit 1;
fi
echo -n "${cmd} ${c} ${n} "
"${rc}" ${cmd} || status=1
[ "${cmd}" = start ] && echo 'ok'
done
done
return ${status}
}
#-------------------------------------------------------------------------------
adm()
{
local cluster=$1 ; shift || :
local id port
if [ -z "$cluster" ]
then
cluster=c1
fi
validate_cluster_name "${cluster}"
id=`cluster_id ${cluster}`
port="10${id}10"
./leofs-adm -p "${port}" "$@"
}
#-------------------------------------------------------------------------------
rmsh()
{
local cluster=$1 ; shift
local node=$1 ; shift
validate_cluster_name "${cluster}"
rc remote_console "${cluster}" "${node}" "$@"
}
#-------------------------------------------------------------------------------
status()
{
local clusters="$1" ; shift || :
local nodes="$1" ; shift || :
local adm_clusters i c n rc status
if [ -z "${clusters}" ]
then
for i in `seq 0 $((NCLUSTERS - 1))`
do
clusters="${clusters} $(cluster_name ${i})"
done
else
for c in ${clusters}
do
validate_cluster_name "${c}"
done
fi
status=0
adm_clusters=
for c in ${clusters}
do
validate_cluster_name "${c}"
if [ -z "${nodes}" ]
then
nodes="manager_0 manager_1"
for i in `seq 0 $((CLUSTER_NSTORAGES - 1))`
do
nodes="${nodes} storage_${i}"
done
nodes="${nodes} gateway_0"
fi
for n in ${nodes}
do
echo -n "status ${c} ${n} "
if rc ping ${c} "${n}" > /dev/null
then
echo up
if [ -z "${run_adm_status}" -a ${n} = manager_0 ]
then
adm_clusters="${adm_clusters} ${c}"
fi
else
echo down
fi
done
done
for c in ${adm_clusters}
do
adm ${c} status
adm ${c} cluster-status
done
return ${status}
}
#-------------------------------------------------------------------------------
# MAIN
#-------------------------------------------------------------------------------
set -e
if [ -z "$1" ]
then
usage
fi
cmd=$1 ; shift
case "${cmd}" in
help|-h|--help)
usage
;;
clean)
clean
;;
deploy)
deploy
;;
start|stop|ping)
rc ${cmd} "$@"
;;
status)
status "$@"
;;
adm)
adm "$@"
;;
rmsh)
[ $# -ge 2 ] || usage
rmsh "$@"
;;
*)
echo "Invalid command: ${cmd}" >&2
usage
;;
esac