forked from apache/incubator-pegasus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·2080 lines (1974 loc) · 62 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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
PID=$$
ROOT=`pwd`
LOCAL_IP=`scripts/get_local_ip`
export REPORT_DIR="$ROOT/test_report"
export DSN_ROOT=$ROOT/DSN_ROOT
export DSN_THIRDPARTY_ROOT=$ROOT/rdsn/thirdparty/output
export LD_LIBRARY_PATH=$DSN_ROOT/lib:$DSN_THIRDPARTY_ROOT/lib:$BOOST_DIR/lib:$LD_LIBRARY_PATH
function usage()
{
echo "usage: run.sh <command> [<args>]"
echo
echo "Command list:"
echo " help print the help info"
echo " build build the system"
echo
echo " start_zk start local single zookeeper server"
echo " stop_zk stop local zookeeper server"
echo " clear_zk stop local zookeeper server and clear data"
echo
echo " start_onebox start pegasus onebox"
echo " stop_onebox stop pegasus onebox"
echo " list_onebox list pegasus onebox"
echo " clear_onebox clear pegasus onebox"
echo
echo " start_onebox_instance start pegasus onebox instance"
echo " stop_onebox_instance stop pegasus onebox instance"
echo " restart_onebox_instance restart pegasus onebox instance"
echo
echo " start_kill_test start pegasus kill test"
echo " stop_kill_test stop pegasus kill test"
echo " list_kill_test list pegasus kill test"
echo " clear_kill_test clear pegasus kill test"
echo
echo " bench run benchmark test"
echo " shell run pegasus shell"
echo " migrate_node migrate primary replicas out of specified node"
echo " downgrade_node downgrade replicas to inactive on specified node"
echo
echo " test run unit test"
echo
echo " pack_server generate pegasus server package for deploy with minos"
echo " pack_client generate pegasus client package"
echo " pack_tools generate pegasus tools package for shell and benchmark test"
echo
echo " bump_version change the version of the project"
echo "Command 'run.sh <command> -h' will print help for subcommands."
}
#####################
## build
#####################
function usage_build()
{
echo "Options for subcommand 'build':"
echo " -h|--help print the help info"
echo " -t|--type build type: debug|release, default is release"
echo " -s|--serialize serialize type: dsn|thrift|proto, default is thrift"
echo " -c|--clear clear rdsn/rocksdb/pegasus before building, not clear thirdparty"
echo " -cc|--half-clear clear pegasus before building, not clear thirdparty/rdsn/rocksdb"
echo " --clear_thirdparty clear thirdparty/rdsn/rocksdb/pegasus before building"
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 building, default no"
echo " --enable_gcov generate gcov code coverage report, default no"
echo " -v|--verbose build in verbose mode, default no"
echo " --disable_gperf build without gperftools, this flag is mainly used"
echo " to enable valgrind memcheck, default no"
echo " --sanitizer <type> build with sanitizer to check potential problems,
type: address|leak|thread|undefined"
echo " --skip_thirdparty whether to skip building thirdparties, default no"
}
function run_build()
{
# Note(jiashuo1): No "memory" check mode, because MemorySanitizer is only available in Clang for Linux x86_64 targets
# # https://www.jetbrains.com/help/clion/google-sanitizers.html
SANITIZERS=("address" "leak" "thread" "undefined")
C_COMPILER="gcc"
CXX_COMPILER="g++"
BUILD_TYPE="release"
CLEAR=NO
PART_CLEAR=NO
CLEAR_THIRDPARTY=NO
JOB_NUM=8
BOOST_DIR=""
WARNING_ALL=NO
ENABLE_GCOV=NO
RUN_VERBOSE=NO
DISABLE_GPERF=NO
SKIP_THIRDPARTY=NO
SANITIZER=""
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
;;
-cc|--part_clear)
PART_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
;;
--sanitizer)
IS_SANITIZERS=`echo ${SANITIZERS[@]} | grep -w $2`
if [[ -z ${IS_SANITIZERS} ]]; then
echo "ERROR: unknown sanitizer type \"$2\""
usage_build
exit 1
fi
SANITIZER="$2"
shift
;;
-v|--verbose)
RUN_VERBOSE=YES
;;
--disable_gperf)
DISABLE_GPERF=YES
;;
--skip_thirdparty)
SKIP_THIRDPARTY=YES
;;
*)
echo "ERROR: unknown option \"$key\""
echo
usage_build
exit 1
;;
esac
shift
done
if [ "$BUILD_TYPE" != "debug" -a "$BUILD_TYPE" != "release" ]; then
echo "ERROR: invalid build type \"$BUILD_TYPE\""
echo
usage_build
exit 1
fi
if [ ! -d $ROOT/rdsn/include ]; then
echo "ERROR: rdsn submodule not fetched"
exit 1
fi
# reset DSN_ROOT env because "$ROOT/DSN_ROOT" is not generated now.
export DSN_ROOT=$ROOT/rdsn/builder/output
if [ ! -e $ROOT/DSN_ROOT ]; then
ln -sf $DSN_ROOT $ROOT/DSN_ROOT
fi
echo "Build start time: `date`"
start_time=`date +%s`
echo "INFO: start build rdsn..."
cd $ROOT/rdsn
OPT="-t $BUILD_TYPE -j $JOB_NUM --compiler $C_COMPILER,$CXX_COMPILER"
if [ "$BOOST_DIR" != "" ]; then
OPT="$OPT -b $BOOST_DIR"
fi
if [ "$CLEAR" == "YES" ]; then
OPT="$OPT -c"
fi
if [ "$CLEAR_THIRDPARTY" == "YES" ]; then
OPT="$OPT --clear_thirdparty"
fi
if [ "$WARNING_ALL" == "YES" ]; then
OPT="$OPT -w"
fi
if [ "$RUN_VERBOSE" == "YES" ]; then
OPT="$OPT -v"
fi
if [ "$ENABLE_GCOV" == "YES" ]; then
OPT="$OPT --enable_gcov"
fi
if [ "$DISABLE_GPERF" == "YES" ]; then
OPT="$OPT --disable_gperf"
fi
if [ "$SKIP_THIRDPARTY" == "YES" ]; then
OPT="$OPT --skip_thirdparty"
fi
if [ ! -z $SANITIZER ]; then
OPT="$OPT --sanitizer $SANITIZER"
fi
./run.sh build $OPT --notest
if [ $? -ne 0 ]; then
echo "ERROR: build rdsn failed"
exit 1
fi
echo "INFO: start build rocksdb..."
ROCKSDB_BUILD_DIR="$ROOT/rocksdb/build"
ROCKSDB_BUILD_OUTPUT="$ROCKSDB_BUILD_DIR/output"
CMAKE_OPTIONS="-DCMAKE_C_COMPILER=$C_COMPILER -DCMAKE_CXX_COMPILER=$CXX_COMPILER -DWITH_LZ4=ON -DWITH_ZSTD=ON -DWITH_SNAPPY=ON -DWITH_BZ2=OFF -DWITH_TESTS=OFF -DCMAKE_CXX_FLAGS=-g"
if [ "$WARNING_ALL" == "YES" ]
then
echo "WARNING_ALL=YES"
CMAKE_OPTIONS="$CMAKE_OPTIONS -DWARNING_ALL=TRUE"
else
echo "WARNING_ALL=NO"
fi
if [ "$ENABLE_GCOV" == "YES" ]
then
echo "ENABLE_GCOV=YES"
CMAKE_OPTIONS="$CMAKE_OPTIONS -DENABLE_GCOV=TRUE"
else
echo "ENABLE_GCOV=NO"
fi
if [ "$BUILD_TYPE" == "debug" ]
then
echo "BUILD_TYPE=debug"
CMAKE_OPTIONS="$CMAKE_OPTIONS -DCMAKE_BUILD_TYPE=RelWithDebInfo"
else
echo "BUILD_TYPE=release"
fi
if [ -f $ROCKSDB_BUILD_DIR/CMAKE_OPTIONS ]
then
LAST_OPTIONS=`cat $ROCKSDB_BUILD_DIR/CMAKE_OPTIONS`
if [ "$CMAKE_OPTIONS" != "$LAST_OPTIONS" ]
then
echo "WARNING: CMAKE_OPTIONS has changed from last build, clear environment first"
CLEAR=YES
fi
fi
if [ "$CLEAR" == "YES" ] && [ -d "$ROCKSDB_BUILD_DIR" ]
then
echo "Clear $ROCKSDB_BUILD_DIR ..."
rm -rf $ROCKSDB_BUILD_DIR
fi
if [ ! -f $ROCKSDB_BUILD_DIR/Makefile ]; then
echo "Running cmake..."
mkdir -p $ROCKSDB_BUILD_DIR
cd $ROCKSDB_BUILD_DIR
echo "$CMAKE_OPTIONS" >CMAKE_OPTIONS
cmake .. -DCMAKE_INSTALL_PREFIX=$ROCKSDB_BUILD_OUTPUT $CMAKE_OPTIONS
if [ $? -ne 0 ]; then
echo "ERROR: cmake failed"
exit 1
fi
else
cd $ROCKSDB_BUILD_DIR
fi
echo "Building..."
if [ "$RUN_VERBOSE" == "YES" ]
then
echo "RUN_VERBOSE=YES"
MAKE_OPTIONS="$MAKE_OPTIONS VERBOSE=1"
else
echo "RUN_VERBOSE=NO"
fi
make install -j $JOB_NUM $MAKE_OPTIONS
if [ $? -ne 0 ]
then
echo "ERROR: build rocksdb failed"
exit 1
else
echo "Build rocksdb succeed"
fi
echo "INFO: start build pegasus..."
cd $ROOT/src
C_COMPILER="$C_COMPILER" CXX_COMPILER="$CXX_COMPILER" BUILD_TYPE="$BUILD_TYPE" \
CLEAR="$CLEAR" PART_CLEAR="$PART_CLEAR" JOB_NUM="$JOB_NUM" \
BOOST_DIR="$BOOST_DIR" WARNING_ALL="$WARNING_ALL" ENABLE_GCOV="$ENABLE_GCOV" SANITIZER="$SANITIZER"\
RUN_VERBOSE="$RUN_VERBOSE" TEST_MODULE="$TEST_MODULE" DISABLE_GPERF="$DISABLE_GPERF" ./build.sh
if [ $? -ne 0 ]; then
echo "ERROR: build pegasus failed"
exit 1
fi
cd $ROOT
chmod +x scripts/*.sh
echo "Build finish time: `date`"
finish_time=`date +%s`
used_time=$((finish_time-start_time))
echo "Build elapsed time: $((used_time/60))m $((used_time%60))s"
}
#####################
## test
#####################
function usage_test()
{
echo "Options for subcommand 'test':"
echo " -h|--help print the help info"
echo " -m|--modules set the test modules: pegasus_unit_test pegasus_function_test"
echo " -k|--keep_onebox whether keep the onebox after the test[default false]"
echo " --on_travis run tests on travis without some time-cosuming function tests"
}
function run_test()
{
local test_modules=""
local clear_flags="1"
local on_travis=""
while [[ $# > 0 ]]; do
key="$1"
case $key in
-h|--help)
usage_test
exit 0
;;
-m|--modules)
test_modules=$2
shift
;;
-k|--keep_onebox)
clear_flags=""
;;
--on_travis)
on_travis="--on_travis"
;;
*)
echo "Error: unknow option \"$key\""
echo
usage_test
exit 1
;;
esac
shift
done
if [ "$test_modules" == "" ]; then
test_modules="pegasus_unit_test pegasus_function_test"
fi
echo "Test start time: `date`"
start_time=`date +%s`
./run.sh clear_onebox #clear the onebox before test
if ! ./run.sh start_onebox -w; then
echo "ERROR: unable to continue on testing because starting onebox failed"
exit 1
fi
for module in `echo $test_modules`; do
pushd $ROOT/src/builder/bin/$module
REPORT_DIR=$REPORT_DIR ./run.sh $on_travis
if [ $? != 0 ]; then
echo "run test \"$module\" in `pwd` failed"
exit 1
fi
popd
done
if [ "$clear_flags" == "1" ]; then
./run.sh clear_onebox
fi
echo "Test finish time: `date`"
finish_time=`date +%s`
used_time=$((finish_time-start_time))
echo "Test elapsed time: $((used_time/60))m $((used_time%60))s"
}
#####################
## start_zk
#####################
function usage_start_zk()
{
echo "Options for subcommand 'start_zk':"
echo " -h|--help print the help info"
echo " -d|--install_dir <dir>"
echo " zookeeper install directory,"
echo " if not set, then default is './.zk_install'"
echo " -p|--port <port> listen port of zookeeper, default is 22181"
}
function run_start_zk()
{
# first we check the environment that zk need: java and nc command
# check java
type java >/dev/null 2>&1 || { echo >&2 "start zk failed, need install jre..."; exit 1;}
# check nc command
type nc >/dev/null 2>&1 || { echo >&2 "start zk failed, need install netcat command..."; exit 1;}
INSTALL_DIR=`pwd`/.zk_install
PORT=22181
while [[ $# > 0 ]]; do
key="$1"
case $key in
-h|--help)
usage_start_zk
exit 0
;;
-d|--install_dir)
INSTALL_DIR=$2
shift
;;
-p|--port)
PORT=$2
shift
;;
*)
echo "ERROR: unknown option \"$key\""
echo
usage_start_zk
exit 1
;;
esac
shift
done
INSTALL_DIR="$INSTALL_DIR" PORT="$PORT" ./scripts/start_zk.sh
if [ $? -ne 0 ]; then
exit 1
fi
}
#####################
## stop_zk
#####################
function usage_stop_zk()
{
echo "Options for subcommand 'stop_zk':"
echo " -h|--help print the help info"
echo " -d|--install_dir <dir>"
echo " zookeeper install directory,"
echo " if not set, then default is './.zk_install'"
}
function run_stop_zk()
{
INSTALL_DIR=`pwd`/.zk_install
while [[ $# > 0 ]]; do
key="$1"
case $key in
-h|--help)
usage_stop_zk
exit 0
;;
-d|--install_dir)
INSTALL_DIR=$2
shift
;;
*)
echo "ERROR: unknown option \"$key\""
echo
usage_stop_zk
exit 1
;;
esac
shift
done
INSTALL_DIR="$INSTALL_DIR" ./scripts/stop_zk.sh
}
#####################
## clear_zk
#####################
function usage_clear_zk()
{
echo "Options for subcommand 'clear_zk':"
echo " -h|--help print the help info"
echo " -d|--install_dir <dir>"
echo " zookeeper install directory,"
echo " if not set, then default is './.zk_install'"
}
function run_clear_zk()
{
INSTALL_DIR=`pwd`/.zk_install
while [[ $# > 0 ]]; do
key="$1"
case $key in
-h|--help)
usage_clear_zk
exit 0
;;
-d|--install_dir)
INSTALL_DIR=$2
shift
;;
*)
echo "ERROR: unknown option \"$key\""
echo
usage_clear__zk
exit 1
;;
esac
shift
done
INSTALL_DIR="$INSTALL_DIR" ./scripts/clear_zk.sh
}
#####################
## start_onebox
#####################
function usage_start_onebox()
{
echo "Options for subcommand 'start_onebox':"
echo " -h|--help print the help info"
echo " -m|--meta_count <num>"
echo " meta server count, default is 3"
echo " -r|--replica_count <num>"
echo " replica server count, default is 3"
echo " -c|--collector"
echo " start the collector server, default not start"
echo " -a|--app_name <str>"
echo " default app name, default is temp"
echo " -p|--partition_count <num>"
echo " default app partition count, default is 8"
echo " -w|--wait_healthy"
echo " wait cluster to become healthy, default not wait"
echo " -s|--server_path <str>"
echo " server binary path, default is ${DSN_ROOT}/bin/pegasus_server"
echo " --config_path"
echo " specify the config template path, default is ./src/server/config.min.ini in non-production env"
echo " ./src/server/config.ini in production env"
echo " --use_product_config"
echo " use the product config template"
}
function run_start_onebox()
{
META_COUNT=3
REPLICA_COUNT=3
COLLECTOR_COUNT=0
APP_NAME=temp
PARTITION_COUNT=8
WAIT_HEALTHY=false
SERVER_PATH=${DSN_ROOT}/bin/pegasus_server
CONFIG_FILE=""
USE_PRODUCT_CONFIG=false
while [[ $# > 0 ]]; do
key="$1"
case $key in
-h|--help)
usage_start_onebox
exit 0
;;
-m|--meta_count)
META_COUNT="$2"
shift
;;
-r|--replica_count)
REPLICA_COUNT="$2"
shift
;;
-c|--collector)
COLLECTOR_COUNT=1
;;
-a|--app_name)
APP_NAME="$2"
shift
;;
-p|--partition_count)
PARTITION_COUNT="$2"
shift
;;
-w|--wait_healthy)
WAIT_HEALTHY=true
;;
-s|--server_path)
SERVER_PATH="$2"
shift
;;
--config_path)
CONFIG_FILE="$2"
shift
;;
--use_product_config)
USE_PRODUCT_CONFIG=true
;;
*)
echo "ERROR: unknown option \"$key\""
echo
usage_start_onebox
exit 1
;;
esac
shift
done
if [ ! -f ${SERVER_PATH}/pegasus_server ]; then
echo "ERROR: file ${SERVER_PATH}/pegasus_server not exist"
exit 1
fi
if ps -ef | grep '/pegasus_server config.ini' | grep -E -q 'app_list meta|app_list replica|app_list collector'; then
echo "ERROR: some onebox processes are running, start failed"
exit 1
fi
ln -s -f "${SERVER_PATH}/pegasus_server" "${ROOT}"
if ! run_start_zk; then
echo "ERROR: unable to setup onebox because zookeeper can not be started"
exit 1
fi
if [ $USE_PRODUCT_CONFIG == "true" ]; then
[ -z "${CONFIG_FILE}" ] && CONFIG_FILE=${ROOT}/src/server/config.ini
[ ! -f "${CONFIG_FILE}" ] && { echo "${CONFIG_FILE} is not exist"; exit 1; }
cp -f ${CONFIG_FILE} ${ROOT}/config-server.ini
sed -i 's/\<34601\>/@META_PORT@/' ${ROOT}/config-server.ini
sed -i 's/\<34801\>/@REPLICA_PORT@/' ${ROOT}/config-server.ini
sed -i 's/%{cluster.name}/onebox/g' ${ROOT}/config-server.ini
sed -i 's/%{network.interface}/eth0/g' ${ROOT}/config-server.ini
sed -i 's/%{email.address}//g' ${ROOT}/config-server.ini
sed -i 's/%{app.dir}/.\/data/g' ${ROOT}/config-server.ini
sed -i 's/%{slog.dir}//g' ${ROOT}/config-server.ini
sed -i 's/%{data.dirs}//g' ${ROOT}/config-server.ini
sed -i 's@%{home.dir}@'"$HOME"'@g' ${ROOT}/config-server.ini
for i in $(seq ${META_COUNT})
do
meta_port=$((34600+i))
if [ $i -eq 1 ]; then
meta_list="${LOCAL_IP}:$meta_port"
else
meta_list="$meta_list,${LOCAL_IP}:$meta_port"
fi
done
sed -i 's/%{meta.server.list}/'"$meta_list"'/g' ${ROOT}/config-server.ini
sed -i 's/%{zk.server.list}/'"${LOCAL_IP}"':22181/g' ${ROOT}/config-server.ini
sed -i 's/app_name = .*$/app_name = '"$APP_NAME"'/' ${ROOT}/config-server.ini
sed -i 's/partition_count = .*$/partition_count = '"$PARTITION_COUNT"'/' ${ROOT}/config-server.ini
else
[ -z "${CONFIG_FILE}" ] && CONFIG_FILE=${ROOT}/src/server/config.min.ini
[ ! -f "${CONFIG_FILE}" ] && { echo "${CONFIG_FILE} is not exist"; exit 1; }
sed "s/@LOCAL_IP@/${LOCAL_IP}/g;s/@APP_NAME@/${APP_NAME}/g;s/@PARTITION_COUNT@/${PARTITION_COUNT}/g" \
${CONFIG_FILE} >${ROOT}/config-server.ini
fi
echo "starting server"
ld_library_path=${SERVER_PATH}:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$ld_library_path
mkdir -p onebox
cd onebox
for i in $(seq ${META_COUNT})
do
meta_port=$((34600+i))
prometheus_port=$((9091+i))
mkdir -p meta$i;
cd meta$i
ln -s -f ${SERVER_PATH}/pegasus_server pegasus_server
sed "s/@META_PORT@/$meta_port/;s/@REPLICA_PORT@/34800/;s/@PROMETHEUS_PORT@/$prometheus_port/" ${ROOT}/config-server.ini >config.ini
echo "cd `pwd` && $PWD/pegasus_server config.ini -app_list meta &>result &"
$PWD/pegasus_server config.ini -app_list meta &>result &
PID=$!
ps -ef | grep '/pegasus_server config.ini' | grep "\<$PID\>"
cd ..
done
for j in $(seq ${REPLICA_COUNT})
do
prometheus_port=$((9091+${META_COUNT}+j))
replica_port=$((34800+j))
mkdir -p replica$j
cd replica$j
ln -s -f ${SERVER_PATH}/pegasus_server pegasus_server
sed "s/@META_PORT@/34600/;s/@REPLICA_PORT@/$replica_port/;s/@PROMETHEUS_PORT@/$prometheus_port/" ${ROOT}/config-server.ini >config.ini
echo "cd `pwd` && $PWD/pegasus_server config.ini -app_list replica &>result &"
$PWD/pegasus_server config.ini -app_list replica &>result &
PID=$!
ps -ef | grep '/pegasus_server config.ini' | grep "\<$PID\>"
cd ..
done
if [ $COLLECTOR_COUNT -eq 1 ]
then
mkdir -p collector
cd collector
ln -s -f ${SERVER_PATH}/pegasus_server pegasus_server
sed "s/@META_PORT@/34600/;s/@REPLICA_PORT@/34800/;s/@PROMETHEUS_PORT@/9091/" ${ROOT}/config-server.ini >config.ini
echo "cd `pwd` && $PWD/pegasus_server config.ini -app_list collector &>result &"
$PWD/pegasus_server config.ini -app_list collector &>result &
PID=$!
ps -ef | grep '/pegasus_server config.ini' | grep "\<$PID\>"
cd ..
fi
if [ $WAIT_HEALTHY == "true" ]; then
cd $ROOT
echo "Wait cluster to become healthy..."
sleeped=0
while true; do
sleep 1
sleeped=$((sleeped+1))
echo "Sleeped for $sleeped seconds"
unhealthy_count=`echo "ls -d" | ./run.sh shell | awk 'f{ if(NF<7){f=0} else if($3!=$4){print} } / fully_healthy /{print;f=1}' | wc -l`
if [ $unhealthy_count -eq 1 ]; then
echo "Cluster becomes healthy."
break
fi
done
fi
}
#####################
## stop_onebox
#####################
function usage_stop_onebox()
{
echo "Options for subcommand 'stop_onebox':"
echo " -h|--help print the help info"
}
function run_stop_onebox()
{
while [[ $# > 0 ]]; do
key="$1"
case $key in
-h|--help)
usage_stop_onebox
exit 0
;;
*)
echo "ERROR: unknown option \"$key\""
echo
usage_stop_onebox
exit 1
;;
esac
shift
done
ps -ef | grep '/pegasus_server config.ini' | grep -E 'app_list meta|app_list replica|app_list collector' | awk '{print $2}' | xargs kill &>/dev/null
}
#####################
## list_onebox
#####################
function usage_list_onebox()
{
echo "Options for subcommand 'list_onebox':"
echo " -h|--help print the help info"
}
function run_list_onebox()
{
while [[ $# > 0 ]]; do
key="$1"
case $key in
-h|--help)
usage_list_onebox
exit 0
;;
*)
echo "ERROR: unknown option \"$key\""
echo
usage_list_onebox
exit 1
;;
esac
shift
done
ps -ef | grep '/pegasus_server config.ini' | grep -E 'app_list meta|app_list replica|app_list collector' | sort -k11
}
#####################
## clear_onebox
#####################
function usage_clear_onebox()
{
echo "Options for subcommand 'clear_onebox':"
echo " -h|--help print the help info"
}
function run_clear_onebox()
{
while [[ $# > 0 ]]; do
key="$1"
case $key in
-h|--help)
usage_clear_onebox
exit 0
;;
*)
echo "ERROR: unknown option \"$key\""
echo
usage_clear_onebox
exit 1
;;
esac
shift
done
run_stop_onebox
run_clear_zk
rm -rf onebox *.log *.data config-*.ini &>/dev/null
sleep 1
}
#####################
## start_onebox_instance
#####################
function usage_start_onebox_instance()
{
echo "Options for subcommand 'start_onebox_instance':"
echo " -h|--help print the help info"
echo " -m|--meta_id <num> start meta server with id"
echo " -r|--replica_id <num> start replica server with id"
echo " -c|--collector start collector server"
}
function run_start_onebox_instance()
{
META_ID=0
REPLICA_ID=0
COLLECTOR_ID=0
while [[ $# > 0 ]]; do
key="$1"
case $key in
-h|--help)
usage_start_onebox_instance
exit 0
;;
-m|--meta_id)
META_ID="$2"
shift
;;
-r|--replica_id)
REPLICA_ID="$2"
shift
;;
-c|--collector)
COLLECTOR_ID=1
;;
*)
echo "ERROR: unknown option \"$key\""
echo
usage_start_onebox_instance
exit 1
;;
esac
shift
done
if [ $META_ID = "0" -a $REPLICA_ID = "0" -a $COLLECTOR_ID = "0" ]; then
echo "ERROR: no meta_id or replica_id or collector set"
exit 1
fi
if [ $META_ID != "0" ]; then
dir=onebox/meta$META_ID
if [ ! -d $dir ]; then
echo "ERROR: invalid meta_id"
exit 1
fi
if ps -ef | grep "/meta$META_ID/pegasus_server config.ini" | grep "app_list meta" ; then
echo "INFO: meta@$META_ID already running"
exit 1
fi
cd $dir
echo "cd `pwd` && $PWD/pegasus_server config.ini -app_list meta &>result &"
$PWD/pegasus_server config.ini -app_list meta &>result &
PID=$!
ps -ef | grep '/pegasus_server config.ini' | grep "\<$PID\>"
cd ..
echo "INFO: meta@$META_ID started"
fi
if [ $REPLICA_ID != "0" ]; then
dir=onebox/replica$REPLICA_ID
if [ ! -d $dir ]; then
echo "ERROR: invalid replica_id"
exit 1
fi
if ps -ef | grep "/replica$REPLICA_ID/pegasus_server config.ini" | grep "app_list replica" ; then
echo "INFO: replica@$REPLICA_ID already running"
exit 1
fi
cd $dir
echo "cd `pwd` && $PWD/pegasus_server config.ini -app_list replica &>result &"
$PWD/pegasus_server config.ini -app_list replica &>result &
PID=$!
ps -ef | grep '/pegasus_server config.ini' | grep "\<$PID\>"
cd ..
echo "INFO: replica@$REPLICA_ID started"
fi
if [ $COLLECTOR_ID != "0" ]; then
dir=onebox/collector
if [ ! -d $dir ]; then
echo "ERROR: collector dir $dir not exist"
exit 1
fi
if ps -ef | grep "/collector/pegasus_server config.ini" | grep "app_list collector" ; then
echo "INFO: collector already running"
exit 1
fi
cd $dir
echo "cd `pwd` && $PWD/pegasus_server config.ini -app_list collector &>result &"
$PWD/pegasus_server config.ini -app_list collector &>result &
PID=$!
ps -ef | grep '/pegasus_server config.ini' | grep "\<$PID\>"
cd ..
echo "INFO: collector started"
fi
}
#####################
## stop_onebox_instance
#####################
function usage_stop_onebox_instance()
{
echo "Options for subcommand 'stop_onebox_instance':"
echo " -h|--help print the help info"
echo " -m|--meta_id <num> stop meta server with id"
echo " -r|--replica_id <num> stop replica server with id"
echo " -c|--collector stop collector server"
}
function run_stop_onebox_instance()
{
META_ID=0
REPLICA_ID=0
COLLECTOR_ID=0
while [[ $# > 0 ]]; do
key="$1"
case $key in
-h|--help)
usage_stop_onebox_instance
exit 0
;;
-m|--meta_id)
META_ID="$2"
shift
;;
-r|--replica_id)
REPLICA_ID="$2"
shift
;;
-c|--collector)
COLLECTOR_ID=1
;;
*)
echo "ERROR: unknown option \"$key\""
echo
usage_stop_onebox_instance
exit 1
;;
esac
shift
done
if [ $META_ID = "0" -a $REPLICA_ID = "0" -a $COLLECTOR_ID = "0" ]; then
echo "ERROR: no meta_id or replica_id or collector set"
exit 1
fi
if [ $META_ID != "0" ]; then
dir=onebox/meta$META_ID
if [ ! -d $dir ]; then
echo "ERROR: invalid meta_id"
exit 1
fi
if ! ps -ef | grep "/meta$META_ID/pegasus_server config.ini" | grep "app_list meta" ; then
echo "INFO: meta@$META_ID is not running"
exit 1
fi
ps -ef | grep "/meta$META_ID/pegasus_server config.ini" | grep "app_list meta" | awk '{print $2}' | xargs kill &>/dev/null
echo "INFO: meta@$META_ID stopped"
fi
if [ $REPLICA_ID != "0" ]; then
dir=onebox/replica$REPLICA_ID
if [ ! -d $dir ]; then
echo "ERROR: invalid replica_id"
exit 1
fi
if ! ps -ef | grep "/replica$REPLICA_ID/pegasus_server config.ini" | grep "app_list replica" ; then
echo "INFO: replica@$REPLICA_ID is not running"
exit 1
fi
ps -ef | grep "/replica$REPLICA_ID/pegasus_server config.ini" | grep "app_list replica" | awk '{print $2}' | xargs kill &>/dev/null
echo "INFO: replica@$REPLICA_ID stopped"
fi
if [ $COLLECTOR_ID != "0" ]; then
if ! ps -ef | grep "/collector/pegasus_server config.ini" | grep "app_list collector" ; then