From 71990de64a45bd7c565c4ed673307a8e62313b9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vedran=20Pri=C5=A1=C4=87an?= Date: Wed, 9 Dec 2020 12:39:07 +0100 Subject: [PATCH 1/2] use netcat if the command exists, set netcat connection timeout to 10 seconds --- wait-for-it.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wait-for-it.sh b/wait-for-it.sh index d990e0d..f28d3b9 100755 --- a/wait-for-it.sh +++ b/wait-for-it.sh @@ -32,8 +32,8 @@ wait_for() WAITFORIT_start_ts=$(date +%s) while : do - if [[ $WAITFORIT_ISBUSY -eq 1 ]]; then - nc -z $WAITFORIT_HOST $WAITFORIT_PORT + if command -v nc &> /dev/null ; then + nc -z -w 10 $WAITFORIT_HOST $WAITFORIT_PORT WAITFORIT_result=$? else (echo -n > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1 From d34c7531aaea08b8d3bc2e9d3e6d22b1eafa4c7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vedran=20Pri=C5=A1=C4=87an?= Date: Wed, 9 Dec 2020 13:42:26 +0100 Subject: [PATCH 2/2] add timeout of 10 seconds for network redirection --- wait-for-it.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wait-for-it.sh b/wait-for-it.sh index f28d3b9..dca4d37 100755 --- a/wait-for-it.sh +++ b/wait-for-it.sh @@ -36,7 +36,7 @@ wait_for() nc -z -w 10 $WAITFORIT_HOST $WAITFORIT_PORT WAITFORIT_result=$? else - (echo -n > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1 + timeout 10 bash -c "(echo -n > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1" WAITFORIT_result=$? fi if [[ $WAITFORIT_result -eq 0 ]]; then