-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetastore.sh
executable file
·86 lines (78 loc) · 1.81 KB
/
metastore.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
#!/bin/bash
set -o errexit # abort on nonzero exitstatus
set -o nounset # abort on unbound variable
set -o pipefail # don't hide errors within pipes
readonly DOCKER="docker"
readonly HIVE_IMAGE_TAG="apache/hive:4.0.0-beta-2-SNAPSHOT"
readonly CONTAINER_NAME="metastore-standalone"
readonly MODE="${1:-}"
container_exists() {
local id
id=$("${DOCKER}" container ls --all --quiet --filter "name=${CONTAINER_NAME}")
if [ "$id" != "" ]
then
return 0
fi
return 1
}
err_retry() {
local exit_code=$1
local attempts=$2
local sleep_millis=$3
shift 3
for attempt in `seq 1 $attempts`; do
echo "Attempt $attempt of $attempts"
# This weird construction lets us capture return codes under -o errexit
"$@" && local rc=$? || local rc=$?
if [[ ! $rc -eq $exit_code ]]; then
return $rc
fi
if [[ $attempt -eq $attempts ]]; then
return $rc
fi
local sleep_s="$((($attempt * $attempt * $sleep_millis) / 1000))"
sleep $sleep_s
done
}
metastore_available() {
(nc -z localhost 9083)
return $?
}
usage() {
echo ""
echo "convenience script to run hive metastore locally for testing"
echo ""
echo "usage: $0 start | await | stop | rm "
}
if [ -z "${MODE}" ]; then
usage
exit 0
fi
case "$MODE" in
"start")
if container_exists
then
echo "Starting a previous container."
${DOCKER} start "${CONTAINER_NAME}"
else
${DOCKER} run --name "${CONTAINER_NAME}" --detach --publish 9083:9083 \
--env SERVICE_OPTS="-Dhive.root.logger=console" \
--env SERVICE_NAME=metastore \
${HIVE_IMAGE_TAG}
fi
;;
"await")
echo "Waiting for metastore availability..."
err_retry 1 5 1000 metastore_available
echo "metastore available!"
;;
"stop")
${DOCKER} kill "${CONTAINER_NAME}"
;;
"rm")
${DOCKER} rm "${CONTAINER_NAME}"
;;
*)
usage
;;
esac