Skip to content

Commit 8b4051d

Browse files
author
Douglas Gibbons
authored
Merge pull request #6 from iturgeon/master
Add support for distros that use Busybox like Alpine
2 parents a2acebe + 8f52a81 commit 8b4051d

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

wait-for-it.sh

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ wait_for()
3232
start_ts=$(date +%s)
3333
while :
3434
do
35-
(echo > /dev/tcp/$HOST/$PORT) >/dev/null 2>&1
36-
result=$?
35+
if [[ $ISBUSY -eq 1 ]]; then
36+
nc -z $HOST $PORT
37+
result=$?
38+
else
39+
(echo > /dev/tcp/$HOST/$PORT) >/dev/null 2>&1
40+
result=$?
41+
fi
3742
if [[ $result -eq 0 ]]; then
3843
end_ts=$(date +%s)
3944
echoerr "$cmdname: $HOST:$PORT is available after $((end_ts - start_ts)) seconds"
@@ -48,9 +53,9 @@ wait_for_wrapper()
4853
{
4954
# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
5055
if [[ $QUIET -eq 1 ]]; then
51-
timeout $TIMEOUT $0 --quiet --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
56+
timeout $BUSYTIMEFLAG $TIMEOUT $0 --quiet --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
5257
else
53-
timeout $TIMEOUT $0 --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
58+
timeout $BUSYTIMEFLAG $TIMEOUT $0 --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
5459
fi
5560
PID=$!
5661
trap "kill -INT -$PID" INT
@@ -136,6 +141,17 @@ STRICT=${STRICT:-0}
136141
CHILD=${CHILD:-0}
137142
QUIET=${QUIET:-0}
138143

144+
# check to see if timeout is from busybox?
145+
# check to see if timeout is from busybox?
146+
TIMEOUT_PATH=$(realpath $(which timeout))
147+
if [[ $TIMEOUT_PATH =~ "busybox" ]]; then
148+
ISBUSY=1
149+
BUSYTIMEFLAG="-t"
150+
else
151+
ISBUSY=0
152+
BUSYTIMEFLAG=""
153+
fi
154+
139155
if [[ $CHILD -gt 0 ]]; then
140156
wait_for
141157
RESULT=$?

0 commit comments

Comments
 (0)