forked from XiaoMi/rdsn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·397 lines (382 loc) · 10.7 KB
/
run.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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
#!/bin/bash
os=linux
scripts_dir=`pwd`/scripts/$os
function exit_if_fail() {
if [ $1 != 0 ]; then
exit $1
fi
}
function usage()
{
echo "usage: run.sh <command> [<args>]"
echo
echo "Command list:"
echo " help print the help info"
echo " build build the system"
echo " install install the system"
echo " test test the system"
echo " start_zk start the local single zookeeper server"
echo " stop_zk stop the local single zookeeper server"
echo " clear_zk stop the local single zookeeper server and clear the data"
echo " format check the code format"
echo " publish publish the program"
echo " publish_docker"
echo " publish the program docker image"
echo " republish republish the program without changes to machinelist and config.ini files"
echo " republish_docker"
echo " republish the program docker image without changes to machinelist and config.ini files"
echo " deploy deploy the program to remote machine"
echo " start start program at remote machine"
echo " stop stop program at remote machine"
echo " clean clean deployed program at remote machine"
echo " k8s_deploy deploy onto kubernetes cluster"
echo " k8s_undeploy"
echo " undeploy from kubernetes cluster"
echo
echo "Command 'run.sh <command> -h' will print help for subcommands."
}
#####################
## build
#####################
function usage_build()
{
subcommand="build"
if [ "$ONLY_BUILD" == "NO" ]; then
subcommand="test"
fi
echo "Options for subcommand '$subcommand':"
echo " -h|--help print the help info"
echo " -t|--type build type: debug|release, default is debug"
echo " -c|--clear clear environment before building, but not clear thirdparty"
echo " --clear_thirdparty clear environment before building, including thirdparty"
echo " --compiler specify c and cxx compiler, sperated by ','"
echo " e.g., \"gcc,g++\" or \"clang-3.9,clang++-3.9\""
echo " default is \"gcc,g++\""
echo " -j|--jobs <num> the number of jobs to run simultaneously, default 8"
echo " -b|--boost_dir <dir> specify customized boost directory, use system boost if not set"
echo " -w|--warning_all open all warnings when build, default no"
echo " --enable_gcov generate gcov code coverage report, default no"
echo " -v|--verbose build in verbose mode, default no"
if [ "$ONLY_BUILD" == "NO" ]; then
echo " -m|--test_module specify modules to test, split by ',',"
echo " e.g., \"dsn.core.tests,dsn.tests\","
echo " if not set, then run all tests"
fi
}
function run_build()
{
C_COMPILER="gcc"
CXX_COMPILER="g++"
BUILD_TYPE="release"
CLEAR=NO
CLEAR_THIRDPARTY=NO
JOB_NUM=8
BOOST_DIR=""
WARNING_ALL=NO
ENABLE_GCOV=NO
RUN_VERBOSE=NO
TEST_MODULE=""
while [[ $# > 0 ]]; do
key="$1"
case $key in
-h|--help)
usage_build
exit 0
;;
-t|--type)
BUILD_TYPE="$2"
shift
;;
-c|--clear)
CLEAR=YES
;;
--clear_thirdparty)
CLEAR_THIRDPARTY=YES
;;
--compiler)
C_COMPILER=`echo $2 | awk -F',' '{print $1}'`
CXX_COMPILER=`echo $2 | awk -F',' '{print $2}'`
if [ "x"$C_COMPILER == "x" -o "x"$CXX_COMPILER == "x" ]; then
echo "ERROR: invalid compiler option: $2"
echo
usage_build
exit 1
fi
shift
;;
-j|--jobs)
JOB_NUM="$2"
shift
;;
-b|--boost_dir)
BOOST_DIR="$2"
shift
;;
-w|--warning_all)
WARNING_ALL=YES
;;
--enable_gcov)
ENABLE_GCOV=YES
;;
-v|--verbose)
RUN_VERBOSE=YES
;;
-m|--test_module)
if [ "$ONLY_BUILD" == "YES" ]; then
echo "ERROR: unknown option \"$key\""
echo
usage_build
exit 1
fi
TEST_MODULE="$2"
shift
;;
*)
echo "ERROR: unknown option \"$key\""
echo
usage_build
exit 1
;;
esac
shift
done
# build thirdparty first
cd thirdparty
if [ "$CLEAR_THIRDPARTY" == "YES" ]; then
echo "Clear thirdparty..."
rm -rf src build output &>/dev/null
CLEAR=YES
fi
./download-thirdparty.sh
exit_if_fail $?
if [ "x"$BOOST_DIR != "x" ]; then
./build-thirdparty.sh -b $BOOST_DIR
exit_if_fail $?
else
./build-thirdparty.sh
exit_if_fail $?
fi
cd ..
if [ "$BUILD_TYPE" != "debug" -a "$BUILD_TYPE" != "release" ]; then
echo "ERROR: invalid build type \"$BUILD_TYPE\""
echo
usage_build
exit 1
fi
if [ "$ONLY_BUILD" == "NO" ]; then
run_start_zk
fi
C_COMPILER="$C_COMPILER" CXX_COMPILER="$CXX_COMPILER" BUILD_TYPE="$BUILD_TYPE" \
ONLY_BUILD="$ONLY_BUILD" CLEAR="$CLEAR" JOB_NUM="$JOB_NUM" \
BOOST_DIR="$BOOST_DIR" WARNING_ALL="$WARNING_ALL" ENABLE_GCOV="$ENABLE_GCOV" \
RUN_VERBOSE="$RUN_VERBOSE" TEST_MODULE="$TEST_MODULE" $scripts_dir/build.sh
}
#####################
## install
#####################
function usage_install()
{
echo "Options for subcommand 'install':"
echo " -h|--help print the help info"
echo " -d|--install_dir <dir>"
echo " specify the install directory,"
echo " if not set, then default is './install'"
}
function run_install()
{
INSTALL_DIR=$DSN_ROOT
if [ ! -d $INSTALL_DIR ]; then
INSTALL_DIR=`pwd`/install
fi
while [[ $# > 0 ]]; do
key="$1"
case $key in
-h|--help)
usage_install
exit 0
;;
-d|--install_dir)
INSTALL_DIR="$2"
shift
;;
*)
echo "ERROR: unknown option \"$key\""
echo
usage_install
exit 1
;;
esac
shift
done
INSTALL_DIR="$INSTALL_DIR" $scripts_dir/install.sh
}
#####################
## start_zk
#####################
function usage_start_zk()
{
echo "Options for subcommand 'start_zk':"
echo " -h|--help print the help info"
echo " -p|--port <port> listen port of zookeeper, default is 12181"
}
function run_start_zk()
{
# download zk before start zk service
# as zk is a 3rdparty dependency of rdsn project,
# so we simply download the whole thirdparty for simplicity
`pwd`/thirdparty/download-thirdparty.sh
exit_if_fail $?
DOWNLOADED_DIR=`pwd`/thirdparty/src
PORT=12181
while [[ $# > 0 ]]; do
key="$1"
case $key in
-h|--help)
usage_start_zk
exit 0
;;
-p|--port)
PORT=$2
shift
;;
*)
echo "ERROR: unknown option \"$key\""
echo
usage_start_zk
exit 1
;;
esac
shift
done
DOWNLOADED_DIR="$DOWNLOADED_DIR" PORT="$PORT" $scripts_dir/start_zk.sh
}
#####################
## stop_zk
#####################
function usage_stop_zk()
{
echo "Options for subcommand 'stop_zk':"
echo " -h|--help print the help info"
}
function run_stop_zk()
{
DOWNLOADED_DIR=`pwd`/thirdparty/src
while [[ $# > 0 ]]; do
key="$1"
case $key in
-h|--help)
usage_stop_zk
exit 0
;;
*)
echo "ERROR: unknown option \"$key\""
echo
usage_stop_zk
exit 1
;;
esac
shift
done
DOWNLOADED_DIR="$DOWNLOADED_DIR" $scripts_dir/stop_zk.sh
}
#####################
## clear_zk
#####################
function usage_clear_zk()
{
echo "Options for subcommand 'clear_zk':"
echo " -h|--help print the help info"
}
function run_clear_zk()
{
DOWNLOADED_DIR=`pwd`/thirdparty/src
while [[ $# > 0 ]]; do
key="$1"
case $key in
-h|--help)
usage_clear_zk
exit 0
;;
*)
echo "ERROR: unknown option \"$key\""
echo
usage_clear__zk
exit 1
;;
esac
shift
done
DOWNLOADED_DIR="$DOWNLOADED_DIR" $scripts_dir/clear_zk.sh
}
#####################
## format
#####################
function usage_format()
{
echo "Options for subcommand 'format':"
echo " -h|--help print the help info"
}
function run_format()
{
while [[ $# > 0 ]]; do
key="$1"
case $key in
-h|--help)
usage_format
exit 0
;;
*)
echo "ERROR: unknown option \"$key\""
echo
usage_format
exit 1
;;
esac
shift
done
$scripts_dir/format.sh
}
####################################################################
if [ $# -eq 0 ]; then
usage
exit 0
fi
cmd=$1
case $cmd in
help)
usage ;;
build)
shift
ONLY_BUILD=YES
run_build $* ;;
install)
shift
run_install $* ;;
test)
shift
ONLY_BUILD=NO
run_build $* ;;
start_zk)
shift
run_start_zk $* ;;
stop_zk)
shift
run_stop_zk $* ;;
clear_zk)
shift
run_clear_zk $* ;;
format)
shift
run_format $* ;;
publish|publish_docker|republish|republish_docker)
$scripts_dir/publish.sh $* ;;
deploy|start|stop|clean)
$scripts_dir/deploy.sh $* ;;
k8s_deploy|k8s_undeploy)
$scripts_dir/k8s_deploy.sh $* ;;
*)
echo "ERROR: unknown command $cmd"
echo
usage
exit 1
esac