Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions wait-for-it.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Usage:
Alternatively, you specify the host and port as host:port
-s | --strict Only execute subcommand if the test succeeds
-q | --quiet Don't output any status messages
-v | --verbose Output each failed attempt to connect
-nc | --netcat Force to use netcat instead of bash tcp detection
-t TIMEOUT | --timeout=TIMEOUT
Timeout in seconds, zero for no timeout
-- COMMAND ARGS Execute command with args after the test finishes
Expand All @@ -32,11 +34,15 @@ wait_for()
WAITFORIT_start_ts=$(date +%s)
while :
do
if [[ $WAITFORIT_ISBUSY -eq 1 ]]; then
nc -z $WAITFORIT_HOST $WAITFORIT_PORT
if [[ $WAITFORIT_ISBUSY -eq 1 ]] || [[ $WAITFORIT_NETCAT -eq 1 ]]; then
nc -z${WAITFORIT_VERBOSE:-} $WAITFORIT_HOST $WAITFORIT_PORT
WAITFORIT_result=$?
else
(echo -n > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1
if [[ -z "$WAITFORIT_VERBOSE" ]]; then
(echo -n > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1
else
(echo -n > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT)
fi
WAITFORIT_result=$?
fi
if [[ $WAITFORIT_result -eq 0 ]]; then
Expand Down Expand Up @@ -81,10 +87,18 @@ do
WAITFORIT_CHILD=1
shift 1
;;
-v| --verbose)
export WAITFORIT_VERBOSE=v
shift 1
;;
-q | --quiet)
WAITFORIT_QUIET=1
shift 1
;;
-nc | --netcat)
export WAITFORIT_NETCAT=1
shift 1
;;
-s | --strict)
WAITFORIT_STRICT=1
shift 1
Expand Down Expand Up @@ -140,6 +154,7 @@ WAITFORIT_TIMEOUT=${WAITFORIT_TIMEOUT:-15}
WAITFORIT_STRICT=${WAITFORIT_STRICT:-0}
WAITFORIT_CHILD=${WAITFORIT_CHILD:-0}
WAITFORIT_QUIET=${WAITFORIT_QUIET:-0}
export WAITFORIT_NETCAT=${WAITFORIT_NETCAT:-0}

# Check to see if timeout is from busybox?
WAITFORIT_TIMEOUT_PATH=$(type -p timeout)
Expand Down