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

Busybox's timeout requires different arguments #5

Closed
iturgeon opened this issue Apr 11, 2016 · 10 comments · May be fixed by #31
Closed

Busybox's timeout requires different arguments #5

iturgeon opened this issue Apr 11, 2016 · 10 comments · May be fixed by #31

Comments

@iturgeon
Copy link
Contributor

I was using wait-for-it on a debian docker container, and all things were great (thanks for the script!).

However, we switched to an Alpine Linux based docker image (which uses busybox) and the script stopped waiting correctly.

As it turns out timeout requires an argument flag for the time. Here's the manual from https://busybox.net/downloads/BusyBox.html

timeout
timeout [-t SECS] [-s SIG] PROG [ARGS]
Runs PROG. Sends SIG to it if it is not gone in SECS seconds. Defaults: SECS: 10, SIG: TERM.

This differs from typical linux usage:

timeout [OPTION] DURATION COMMAND [ARG]...

Changing lines 52 and 54 where timeout is used by prepending -t before the $TIMEOUT causes it to work.

Here's the working result:

wait_for_wrapper()
{
    # In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
    if [[ $QUIET -eq 1 ]]; then
        timeout -t $TIMEOUT $0 --quiet --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
    else
        timeout -t $TIMEOUT $0 --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
    fi
    PID=$!
    trap "kill -INT -$PID" INT
    wait $PID
    RESULT=$?
    if [[ $RESULT -ne 0 ]]; then
        echoerr "$cmdname: timeout occurred after waiting $TIMEOUT seconds for $HOST:$PORT"
    fi
    return $RESULT
}

I did a quick search for a simple method to determine if busybox is being used, not sure what the best solution would be. Worst case - this post may help others in a similar situation.

@vishnubob
Copy link
Owner

While I like the idea of simultaneously supporting busybox, the problem is that busybox doesn't seem to support the /dev/tcp extension that is built into bash, which is an intrinsic requirement of wait-for-it. If you have different information, please let me know.

@iturgeon
Copy link
Contributor Author

Perhaps netcat could substitute?

nc -z $HOST $PORT seems like it's behaving similarly to /dev/tcp. nc appears to be part of busy box too. Though I don't really know the implications of switching or falling back. I guess "pure bash" may still prevent it's use.

@iturgeon
Copy link
Contributor Author

Also of note in this case, echoerr "$cmdname: timeout occurred after waiting $TIMEOUT seconds for $HOST:$PORT" is executed immediately after timeout fails with a status code of 127.

I'm wondering if it might be preferable that the script just waits the maximum time?

@vishnubob
Copy link
Owner

If you are interested in adding support for busybox, please feel free to fork this repository and adjust it to your needs. If your modifications provide simultaneous compatibility with bash, I would welcome a pull request.

@Vanuan
Copy link

Vanuan commented Apr 17, 2016

@vishnubob have you looked into #6 yet?

@mahnunchik
Copy link

mahnunchik commented Apr 18, 2016

+1

bash-4.3# wait-for-it google.com:80
timeout: can't execute '15': No such file or directory
wait-for-it: timeout occurred after waiting 15 seconds for google.com:80

@tompluess
Copy link

#31 fixes the call to timeout on busybox while not breaking the the call to timeout on debian.

@douglas-gibbons
Copy link
Collaborator

Busybox support added with this pull request. Note that this does require bash to be installed on busybox.

@davidghiurco
Copy link

@iturgeon Thanks for posting this!! Helped me figure out why timeout was not working when switching from a fat ubuntu docker image to alpine.

@socketpair
Copy link

See mirror/busybox@c9720a7

LOL, Busybox has fixed that. Newer busybox will not wok with workaround made for old one (!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants