forked from oss-tsukuba/nextcloud-gfarm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wait.sh
executable file
·54 lines (44 loc) · 983 Bytes
/
wait.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
#!/bin/bash
set -eu
#set -x
URL_PATH="/"
NAME="Nextcloud-Gfarm"
CONT_NAME="nextcloud"
EXPECT_CODE='^30.*$'
SILENT="-s"
#SILENT=""
COMPOSE=$(make -s ECHO_COMPOSE)
eval $(cat config.env | egrep '^(PROTOCOL|HTTP_PORT|HTTPS_PORT|SERVER_NAME)=')
if [ "${PROTOCOL}" = "https" ]; then
PORT=${HTTPS_PORT:-443}
else
PORT=${HTTP_PORT:-80}
fi
URL="${PROTOCOL}://${SERVER_NAME}:${PORT}${URL_PATH}"
RESOLVE="--resolve ${SERVER_NAME}:${PORT}:127.0.0.1"
container_exists()
{
${COMPOSE} exec ${CONT_NAME} true
}
http_get_code()
{
curl ${SILENT} -k --noproxy '*' -w '%{http_code}' \
${RESOLVE} ${URL} -o /dev/null
}
echo -n "Waiting for ${NAME} startup..."
while :; do
if ! container_exists; then
make stop ${CONT_NAME}
make logs | tail -20
exit 1
fi
if CODE=$(http_get_code); then
if [[ "$CODE" =~ ${EXPECT_CODE} ]]; then
break
fi
fi
echo -n .
sleep 1
done
echo
echo "${NAME} is ready."