Commit
·
0ca50fb
1
Parent(s):
e40eebc
restored app/scripts/wait-for-it.sh .. accidentally rm
Browse files- app/scripts/wait-for-it.sh +205 -0
- docker-compose.yml +1 -1
app/scripts/wait-for-it.sh
ADDED
@@ -0,0 +1,205 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env bash
|
2 |
+
# Use this script to test if a given TCP host/port are available
|
3 |
+
|
4 |
+
# --------------
|
5 |
+
# wait-for-it.sh
|
6 |
+
# --------------
|
7 |
+
# Original author @vishubob on GH https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh
|
8 |
+
# Modified for HTTP OK 200 support by @paulpierre
|
9 |
+
|
10 |
+
|
11 |
+
WAITFORIT_cmdname=${0##*/}
|
12 |
+
|
13 |
+
echoerr() { if [[ $WAITFORIT_QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }
|
14 |
+
|
15 |
+
usage()
|
16 |
+
{
|
17 |
+
cat << USAGE >&2
|
18 |
+
Usage:
|
19 |
+
$WAITFORIT_cmdname host:port [-s] [-t timeout] [-- command args]
|
20 |
+
-h HOST | --host=HOST Host or IP under test
|
21 |
+
-p PORT | --port=PORT TCP port under test
|
22 |
+
Alternatively, you specify the host and port as host:port
|
23 |
+
-s | --strict Only execute subcommand if the test succeeds
|
24 |
+
-q | --quiet Don't output any status messages
|
25 |
+
-t TIMEOUT | --timeout=TIMEOUT
|
26 |
+
Timeout in seconds, zero for no timeout
|
27 |
+
-- COMMAND ARGS Execute command with args after the test finishes
|
28 |
+
USAGE
|
29 |
+
exit 1
|
30 |
+
}
|
31 |
+
wait_for()
|
32 |
+
{
|
33 |
+
local proto="tcp"
|
34 |
+
if [[ $WAITFORIT_HTTP_OK -eq 1 ]]; then
|
35 |
+
proto="http"
|
36 |
+
fi
|
37 |
+
|
38 |
+
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
|
39 |
+
echoerr "$WAITFORIT_cmdname: waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT to be available ($proto)"
|
40 |
+
else
|
41 |
+
echoerr "$WAITFORIT_cmdname: waiting for $WAITFORIT_HOST:$WAITFORIT_PORT to be available ($proto) without a timeout"
|
42 |
+
fi
|
43 |
+
|
44 |
+
WAITFORIT_start_ts=$(date +%s)
|
45 |
+
while :
|
46 |
+
do
|
47 |
+
if [[ $WAITFORIT_HTTP_OK -eq 1 ]]; then
|
48 |
+
response=$(echo -e "HEAD / HTTP/1.1\r\nHost: $WAITFORIT_HOST:$WAITFORIT_PORT\r\nConnection: close\r\n\r\n" | nc -w 5 $WAITFORIT_HOST $WAITFORIT_PORT | head -n1)
|
49 |
+
if [[ $response =~ "200 OK" ]]; then
|
50 |
+
WAITFORIT_result=0
|
51 |
+
else
|
52 |
+
WAITFORIT_result=1
|
53 |
+
fi
|
54 |
+
else
|
55 |
+
(echo -n > /dev/$proto/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1
|
56 |
+
WAITFORIT_result=$?
|
57 |
+
fi
|
58 |
+
|
59 |
+
if [[ $WAITFORIT_result -eq 0 ]]; then
|
60 |
+
WAITFORIT_end_ts=$(date +%s)
|
61 |
+
echoerr "$WAITFORIT_cmdname: $WAITFORIT_HOST:$WAITFORIT_PORT is available after $((WAITFORIT_end_ts - WAITFORIT_start_ts)) seconds"
|
62 |
+
break
|
63 |
+
fi
|
64 |
+
sleep 1
|
65 |
+
done
|
66 |
+
return $WAITFORIT_result
|
67 |
+
}
|
68 |
+
|
69 |
+
wait_for_wrapper()
|
70 |
+
{
|
71 |
+
# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
|
72 |
+
if [[ $WAITFORIT_QUIET -eq 1 ]]; then
|
73 |
+
timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --quiet --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
|
74 |
+
else
|
75 |
+
timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
|
76 |
+
fi
|
77 |
+
WAITFORIT_PID=$!
|
78 |
+
trap "kill -INT -$WAITFORIT_PID" INT
|
79 |
+
wait $WAITFORIT_PID
|
80 |
+
WAITFORIT_RESULT=$?
|
81 |
+
if [[ $WAITFORIT_RESULT -ne 0 ]]; then
|
82 |
+
echoerr "$WAITFORIT_cmdname: timeout occurred after waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
|
83 |
+
fi
|
84 |
+
return $WAITFORIT_RESULT
|
85 |
+
}
|
86 |
+
|
87 |
+
# process arguments
|
88 |
+
while [[ $# -gt 0 ]]
|
89 |
+
do
|
90 |
+
case "$1" in
|
91 |
+
*:* )
|
92 |
+
WAITFORIT_hostport=(${1//:/ })
|
93 |
+
WAITFORIT_HOST=${WAITFORIT_hostport[0]}
|
94 |
+
WAITFORIT_PORT=${WAITFORIT_hostport[1]}
|
95 |
+
shift 1
|
96 |
+
;;
|
97 |
+
-o | --http-ok)
|
98 |
+
WAITFORIT_HTTP_OK=1
|
99 |
+
shift 1
|
100 |
+
;;
|
101 |
+
--child)
|
102 |
+
WAITFORIT_CHILD=1
|
103 |
+
shift 1
|
104 |
+
;;
|
105 |
+
-q | --quiet)
|
106 |
+
WAITFORIT_QUIET=1
|
107 |
+
shift 1
|
108 |
+
;;
|
109 |
+
-s | --strict)
|
110 |
+
WAITFORIT_STRICT=1
|
111 |
+
shift 1
|
112 |
+
;;
|
113 |
+
-h)
|
114 |
+
WAITFORIT_HOST="$2"
|
115 |
+
if [[ $WAITFORIT_HOST == "" ]]; then break; fi
|
116 |
+
shift 2
|
117 |
+
;;
|
118 |
+
--host=*)
|
119 |
+
WAITFORIT_HOST="${1#*=}"
|
120 |
+
shift 1
|
121 |
+
;;
|
122 |
+
-p)
|
123 |
+
WAITFORIT_PORT="$2"
|
124 |
+
if [[ $WAITFORIT_PORT == "" ]]; then break; fi
|
125 |
+
shift 2
|
126 |
+
;;
|
127 |
+
--port=*)
|
128 |
+
WAITFORIT_PORT="${1#*=}"
|
129 |
+
shift 1
|
130 |
+
;;
|
131 |
+
-t)
|
132 |
+
WAITFORIT_TIMEOUT="$2"
|
133 |
+
if [[ $WAITFORIT_TIMEOUT == "" ]]; then break; fi
|
134 |
+
shift 2
|
135 |
+
;;
|
136 |
+
--timeout=*)
|
137 |
+
WAITFORIT_TIMEOUT="${1#*=}"
|
138 |
+
shift 1
|
139 |
+
;;
|
140 |
+
--)
|
141 |
+
shift
|
142 |
+
WAITFORIT_CLI=("$@")
|
143 |
+
break
|
144 |
+
;;
|
145 |
+
--help)
|
146 |
+
usage
|
147 |
+
;;
|
148 |
+
*)
|
149 |
+
echoerr "Unknown argument: $1"
|
150 |
+
usage
|
151 |
+
;;
|
152 |
+
esac
|
153 |
+
done
|
154 |
+
|
155 |
+
if [[ "$WAITFORIT_HOST" == "" || "$WAITFORIT_PORT" == "" ]]; then
|
156 |
+
echoerr "Error: you need to provide a host and port to test."
|
157 |
+
usage
|
158 |
+
fi
|
159 |
+
|
160 |
+
WAITFORIT_TIMEOUT=${WAITFORIT_TIMEOUT:-15}
|
161 |
+
WAITFORIT_STRICT=${WAITFORIT_STRICT:-0}
|
162 |
+
WAITFORIT_CHILD=${WAITFORIT_CHILD:-0}
|
163 |
+
WAITFORIT_QUIET=${WAITFORIT_QUIET:-0}
|
164 |
+
WAITFORIT_HTTP_OK=${WAITFORIT_HTTP_OK:-0}
|
165 |
+
|
166 |
+
|
167 |
+
# Check to see if timeout is from busybox?
|
168 |
+
WAITFORIT_TIMEOUT_PATH=$(type -p timeout)
|
169 |
+
WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH)
|
170 |
+
|
171 |
+
WAITFORIT_BUSYTIMEFLAG=""
|
172 |
+
if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then
|
173 |
+
WAITFORIT_ISBUSY=1
|
174 |
+
# Check if busybox timeout uses -t flag
|
175 |
+
# (recent Alpine versions don't support -t anymore)
|
176 |
+
if timeout &>/dev/stdout | grep -q -e '-t '; then
|
177 |
+
WAITFORIT_BUSYTIMEFLAG="-t"
|
178 |
+
fi
|
179 |
+
else
|
180 |
+
WAITFORIT_ISBUSY=0
|
181 |
+
fi
|
182 |
+
|
183 |
+
if [[ $WAITFORIT_CHILD -gt 0 ]]; then
|
184 |
+
wait_for
|
185 |
+
WAITFORIT_RESULT=$?
|
186 |
+
exit $WAITFORIT_RESULT
|
187 |
+
else
|
188 |
+
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
|
189 |
+
wait_for_wrapper
|
190 |
+
WAITFORIT_RESULT=$?
|
191 |
+
else
|
192 |
+
wait_for
|
193 |
+
WAITFORIT_RESULT=$?
|
194 |
+
fi
|
195 |
+
fi
|
196 |
+
|
197 |
+
if [[ $WAITFORIT_CLI != "" ]]; then
|
198 |
+
if [[ $WAITFORIT_RESULT -ne 0 && $WAITFORIT_STRICT -eq 1 ]]; then
|
199 |
+
echoerr "$WAITFORIT_cmdname: strict mode, refusing to execute subprocess"
|
200 |
+
exit $WAITFORIT_RESULT
|
201 |
+
fi
|
202 |
+
exec "${WAITFORIT_CLI[@]}"
|
203 |
+
else
|
204 |
+
exit $WAITFORIT_RESULT
|
205 |
+
fi
|
docker-compose.yml
CHANGED
@@ -73,7 +73,7 @@ services:
|
|
73 |
|
74 |
ports:
|
75 |
- 5005:5005
|
76 |
-
entrypoint: ["/bin/bash", "-c", "chmod +x /wait-for-it.sh && /wait-for-it.sh rasa-credentials:8889 -t 120 -o && rasa run --enable-api --cors '*' --debug --credentials /app/credentials.yml --endpoints /app/endpoints.yml --model /app/models"]
|
77 |
networks:
|
78 |
- chat-network
|
79 |
depends_on:
|
|
|
73 |
|
74 |
ports:
|
75 |
- 5005:5005
|
76 |
+
entrypoint: ["/bin/bash", "-c", "chmod +x /app/wait-for-it.sh && /app/wait-for-it.sh rasa-credentials:8889 -t 120 -o && rasa run --enable-api --cors '*' --debug --credentials /app/credentials.yml --endpoints /app/endpoints.yml --model /app/models"]
|
77 |
networks:
|
78 |
- chat-network
|
79 |
depends_on:
|