-
Notifications
You must be signed in to change notification settings - Fork 378
Expand file tree
/
Copy pathwait-for-db.sh
More file actions
executable file
·114 lines (87 loc) · 2.82 KB
/
wait-for-db.sh
File metadata and controls
executable file
·114 lines (87 loc) · 2.82 KB
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
#!/bin/bash
# The purpose of this script is to be called after `docker compose up -d` has been run for a given database
# The idea is to block until the database is available to serve requests. Once the database can serve requests,
# the integration tests can be run.
# Therefore, the ports etc are tightly coupled with the compose.yml files under tests/core/engine_adapter/docker/
#
# Note that if the docker daemon is not running `localhost`, you can set the DOCKER_HOSTNAME environment variable to the
# correct host Docker is running on
set -e
if [ -z "$1" ]; then
echo "USAGE: $0 <engine>"
exit 1
fi
ENGINE="$1"
function_exists() {
declare -f -F $1 > /dev/null
return $?
}
probe_port() {
HOSTNAME=${DOCKER_HOSTNAME:-localhost}
echo "Probing '$HOSTNAME' on port $1"
while ! nc -z $HOSTNAME $1; do
sleep 1
done
}
clickhouse_ready() {
probe_port 8123
}
postgres_ready() {
probe_port 5432
}
mssql_ready() {
probe_port 1433
}
mysql_ready() {
probe_port 3306
}
spark_ready() {
probe_port 15002
}
starrocks_ready() {
probe_port 9030
echo "Checking for 1 alive StarRocks backends..."
sleep 5
while true; do
echo "Checking StarRocks backends..."
ALIVE_BACKENDS=$(docker exec -i starrocks-fe mysql -h127.0.0.1 -P9030 -uroot -e "show backends \G" | grep -c "^ *Alive: true *$")
# fallback value if failed to get number
if ! [[ "$ALIVE_BACKENDS" =~ ^[0-9]+$ ]]; then
echo "WARN: Unable to parse number of alive backends, got: '$ALIVE_BACKENDS'"
ALIVE_BACKENDS=0
fi
echo "Found $ALIVE_BACKENDS alive backends"
if [ "$ALIVE_BACKENDS" -ge 1 ]; then
echo "StarRocks has 1 or more alive backends"
break
fi
echo "Waiting for more backends to become alive..."
sleep 5
done
# set default replication num to 1 (there is only one be in the docker compose file)
docker exec -i starrocks-fe mysql -h127.0.0.1 -P9030 -uroot -e "ADMIN SET frontend config ('default_replication_num' = '1');"
}
trino_ready() {
# Trino has a built-in healthcheck script, just call that
docker compose -f tests/core/engine_adapter/integration/docker/compose.trino.yaml exec trino /bin/bash -c '/usr/lib/trino/bin/health-check'
}
risingwave_ready() {
probe_port 4566
}
echo "Waiting for $ENGINE to be ready..."
READINESS_FUNC="${ENGINE}_ready"
# If called with an unimplemented / unsupported engine, just exit
if ! function_exists $READINESS_FUNC ; then
echo "WARN: $READINESS_FUNC not implemeted; exiting"
exit 0
fi
EXIT_CODE=1
while [ $EXIT_CODE -ne 0 ]; do
echo "Checking $ENGINE"
$READINESS_FUNC && EXIT_CODE=$? || EXIT_CODE=$?
if [ $EXIT_CODE -ne 0 ]; then
echo "$ENGINE not ready; sleeping"
sleep 5
fi
done
echo "$ENGINE is ready!"