From 400fb17f6500cc95913a683105d6919b524bd7ef Mon Sep 17 00:00:00 2001 From: Tom Pluss Date: Tue, 11 Apr 2017 11:18:35 +0000 Subject: [PATCH] refactor: TIMEOUT_OPTION depending on busybox --- wait-for-it.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/wait-for-it.sh b/wait-for-it.sh index eca6c3b..a53a579 100755 --- a/wait-for-it.sh +++ b/wait-for-it.sh @@ -46,12 +46,21 @@ wait_for() wait_for_wrapper() { - # In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692 if [[ $QUIET -eq 1 ]]; then - timeout $TIMEOUT $0 --quiet --child --host=$HOST --port=$PORT --timeout=$TIMEOUT & + QUIET_OPTION="--quiet" else - timeout $TIMEOUT $0 --child --host=$HOST --port=$PORT --timeout=$TIMEOUT & + QUIET_OPTION="" fi + ls -l `which timeout` | grep busybox > /dev/null + if [[ $? -eq 0 ]]; then + # echo $cmdname: using busybox timeout + TIMEOUT_OPTION="-t $TIMEOUT" + else + # echo $cmdname: using native timeout + TIMEOUT_OPTION="$TIMEOUT" + fi + # In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692 + timeout $TIMEOUT_OPTION $0 $QUIET_OPTION --child --host=$HOST --port=$PORT & PID=$! trap "kill -INT -$PID" INT wait $PID