-
Notifications
You must be signed in to change notification settings - Fork 35
/
playground.sh
executable file
·143 lines (127 loc) · 3.43 KB
/
playground.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
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
set -x
playground_dir="$(dirname "${BASH_SOURCE-$0}")"
playground_dir="$(
cd "${playground_dir}" >/dev/null
pwd
)"
testDocker() {
echo "INFO: Testing Docker environment by running hello-world..."
docker run --pull always hello-world >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "INFO: Docker is working correctly!"
else
echo "ERROR: There was an issue running the hello-world container. Please check your Docker installation."
exit 1
fi
}
checkCompose() {
isExist=$(which docker-compose)
if [ $isExist ]; then
true # Placeholder, do nothing
else
echo "ERROR: No docker service environment found. Please install docker-compose."
exit
fi
}
checkPortInUse() {
local port=$1
if [[ "$(uname)" == "Darwin" ]]; then
openPort=$(lsof -i :$port -sTCP:LISTEN)
elif [[ "$(uname)" == "Linux" ]]; then
echo "Checking ports with sudo permission ..."
openPort=$(sudo lsof -i :$port -sTCP:LISTEN)
fi
if [ -z "${openPort}" ]; then
echo "INFO: Port $port is ok."
else
echo "ERROR: Port $port is in use. Please check it."
exit 1
fi
}
start() {
echo "INFO: Starting the playground..."
testDocker
checkCompose
ports=(8090 9001 3307 19000 19083 60070 13306 15342 18080 18888 19090 13000)
for port in "${ports[@]}"; do
checkPortInUse ${port}
done
cd ${playground_dir}
echo "Preparing packages..."
./init/spark/spark-dependency.sh
./init/gravitino/gravitino-dependency.sh
./init/jupyter/jupyter-dependency.sh
logSuffix=$(date +%Y%m%d%H%m%s)
if [ "$enableRanger" == true ]; then
docker-compose -f docker-compose.yaml -f docker-enable-ranger-hive-override.yaml up --detach
else
docker-compose up --detach
fi
docker compose logs -f >${playground_dir}/playground-${logSuffix}.log 2>&1 &
echo "Check log details: ${playground_dir}/playground-${logSuffix}.log"
}
status() {
docker-compose ps -a
}
stop() {
echo "INFO: Stopping the playground..."
docker-compose down
if [ $? -eq 0 ]; then
echo "INFO: Playground stopped!"
fi
}
case "$1" in
start)
if [[ "$2" == "-y" ]]; then
input="y"
else
echo "The playground requires 2 CPU cores, 8 GB of RAM, and 25 GB of disk storage to operate efficiently."
read -r -p "Confirm the requirement is available in your OS [Y/n]:" input
fi
if [[ "$2" == "--enable-ranger" || "$3" == "--enable-ranger" ]]; then
enableRanger=true
else
enableRanger=false
fi
case $input in
[yY][eE][sS] | [yY]) ;;
[nN][oO] | [nN])
exit 0
;;
*)
echo "ERROR: Invalid input!"
exit 1
;;
esac
start
;;
status)
status
;;
stop)
stop
;;
*)
echo "Usage: $0 [start | status | stop]"
exit 1
;;
esac