forked from cubefs/cubefs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_docker.sh
executable file
·154 lines (135 loc) · 3.38 KB
/
run_docker.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
#! /bin/bash
set -e
RootPath=$(cd $(dirname $0)/..; pwd)
GOPATH=/go
export DiskPath="$RootPath/docker/docker_data"
MIN_DNDISK_AVAIL_SIZE_GB=10
help() {
cat <<EOF
Usage: ./run_docker.sh [ -h | --help ] [ -d | --disk </disk/path> ] [ -l | --ltptest ]
-h, --help show help info
-d, --disk </disk/path> set ChubaoFS DataNode local disk path
-b, --build build ChubaoFS server and client
-s, --server start ChubaoFS servers docker image
-c, --client start ChubaoFS client docker image
-m, --monitor start monitor web ui
-l, --ltptest run ltp test
-r, --run run servers, client and monitor
--clean cleanup old docker image
EOF
exit 0
}
clean() {
docker-compose -f ${RootPath}/docker/docker-compose.yml down
}
# unit test
run_unit_test() {
docker-compose -f ${RootPath}/docker/docker-compose.yml run unit_test
}
# build
build() {
docker-compose -f ${RootPath}/docker/docker-compose.yml run build
}
# start server
start_servers() {
isDiskAvailable $DiskPath
mkdir -p ${DiskPath}/disk/{1..4}
docker-compose -f ${RootPath}/docker/docker-compose.yml up -d servers
}
start_client() {
docker-compose -f ${RootPath}/docker/docker-compose.yml run client bash -c "/cfs/script/start_client.sh ; /bin/bash"
}
start_monitor() {
docker-compose -f ${RootPath}/docker/docker-compose.yml up -d monitor
}
start_ltptest() {
docker-compose -f ${RootPath}/docker/docker-compose.yml run client
}
run_ltptest() {
build
start_servers
start_ltptest
}
run() {
build
start_monitor
start_servers
start_client
}
cmd="help"
ARGS=( "$@" )
for opt in ${ARGS[*]} ; do
case "$opt" in
-h|--help)
help
;;
-b|--build)
cmd=build
;;
-t|--test)
cmd=run_test
;;
-l|--ltptest)
cmd=run_ltptest
;;
-r|--run)
cmd=run
;;
-s|--server)
cmd=run_servers
;;
-c|--client)
cmd=run_client
;;
-m|--monitor)
cmd=run_monitor
;;
-clean|--clean)
cmd=clean
;;
*)
;;
esac
done
function isDiskAvailable() {
Disk=${1:-"need diskpath"}
[[ -d $Disk ]] || mkdir -p $Disk
if [[ ! -d $Disk ]] ; then
echo "error: $DiskPath must be exist and at least 10GB free size"
exit 1
fi
avail_kb=$(df -k $Disk | tail -1 | awk '{print $4}')
avail_GB=$(( $avail_kb / 1000 / 1000 ))
if (( $avail_GB < $MIN_DNDISK_AVAIL_SIZE_GB )) ; then
echo "$Disk: avaible size $avail_GB GB < Min Disk avaible size $MIN_DNDISK_AVAIL_SIZE_GB GB" ;
exit 1
fi
}
for opt in ${ARGS[*]} ; do
case "-$1" in
--d|---disk)
shift
export DiskPath=${1:?"need disk dir path"}
isDiskAvailable $DiskPath
shift
;;
-)
break
;;
*)
shift
;;
esac
done
case "-$cmd" in
-help) help ;;
-run) run ;;
-build) build ;;
-run_servers) start_servers ;;
-run_client) start_client ;;
-run_monitor) start_monitor ;;
-run_ltptest) run_ltptest ;;
-run_test) run_unit_test ;;
-clean) clean ;;
*) help ;;
esac