/
wait-for-db.sh
executable file
·72 lines (57 loc) · 1.24 KB
/
wait-for-db.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
#!/usr/bin/env bash
#set -x
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-h|--host)
HOST="$2"
shift # past argument
shift # past value
;;
-t|--timeout)
TIMEOUT="$2"
shift # past argument
shift # past value
;;
-n|--name)
NAME="$3"
shift # past argument
shift # past value
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
if [[ -z "${HOST}" ]]; then
HOST="localhost:7200"
fi
if [[ -z "${TIMEOUT}" ]]; then
TIMEOUT=360
fi
if [[ -z "${NAME}" ]]; then
NAME="knora-test-unit"
fi
poll-db() {
# STATUS=$(curl -s -o /dev/null -w '%{http_code}' http://${HOST}/repositories/${NAME}/health?)
STATUS=$(curl -s -o /dev/null -w '%{http_code}' http://${HOST}/rest/repositories)
if [ "${STATUS}" -eq 200 ]; then
echo "==> DB started"
return 0
else
return 1
fi
}
attempt_counter=0
until poll-db; do
if [ ${attempt_counter} -eq ${TIMEOUT} ]; then
echo "Timed out waiting for DB to start"
exit 1
fi
attempt_counter=$((attempt_counter+1))
sleep 1
done