Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding and optional delay after the test succeeds to trigger the command. #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
8 changes: 8 additions & 0 deletions wait-for-it.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Usage:
-q | --quiet Don't output any status messages
-t TIMEOUT | --timeout=TIMEOUT
Timeout in seconds, zero for no timeout
-d delay | --delay=DELAY
Delay in seconds after the test succeeds to trigger the command. zero for no timeout (default).
-- COMMAND ARGS Execute command with args after the test finishes
USAGE
exit 1
Expand Down Expand Up @@ -85,6 +87,10 @@ do
WAITFORIT_QUIET=1
shift 1
;;
-d | --delay)
Copy link

@bartelemi bartelemi Sep 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code won't work if you provide --delay=X, where X is an integer. To align with how remaining arguments are parsed in this script, you need to split handling -d and --delay like this:

-d)
WAITFORIT_DELAY="$2"
shift 2
;;
--delay=*)
WAITFORIT_DELAY="${1#*=}"
shift 1
;;

WAITFORIT_DELAY=1
shift 1
;;
-s | --strict)
WAITFORIT_STRICT=1
shift 1
Expand Down Expand Up @@ -140,6 +146,7 @@ WAITFORIT_TIMEOUT=${WAITFORIT_TIMEOUT:-15}
WAITFORIT_STRICT=${WAITFORIT_STRICT:-0}
WAITFORIT_CHILD=${WAITFORIT_CHILD:-0}
WAITFORIT_QUIET=${WAITFORIT_QUIET:-0}
WAITFORIT_DELAY=${WAITFORIT_DELAY:-0}

# check to see if timeout is from busybox?
WAITFORIT_TIMEOUT_PATH=$(type -p timeout)
Expand Down Expand Up @@ -172,6 +179,7 @@ if [[ $WAITFORIT_CLI != "" ]]; then
echoerr "$WAITFORIT_cmdname: strict mode, refusing to execute subprocess"
exit $WAITFORIT_RESULT
fi
sleep ${WAITFORIT_DELAY}
exec "${WAITFORIT_CLI[@]}"
else
exit $WAITFORIT_RESULT
Expand Down