Skip to content

Commit

Permalink
when on OSX, use all relevant nc timeout options
Browse files Browse the repository at this point in the history
  • Loading branch information
ikatz-drizly committed Oct 25, 2018
1 parent d101d61 commit 67a77ef
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions wait-for
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,20 @@ USAGE
exit "$exitcode"
}

test_connection() {
# force a 1-second timeout on darwin (https://stackoverflow.com/a/20460402/2063546)
if [ -z "${$OSTYPE##*darwin*}" ] ; then
nc -w 1 -G 1 "$1" "$2" > /dev/null 2>&1
else
nc -w 1 "$1" "$2" > /dev/null 2>&1
fi
}

wait_for() {
for i in `seq $TIMEOUT` ; do
# use a 1-second timeout
nc -w 1 -z "$HOST" "$PORT" > /dev/null 2>&1
# use a 1-second timeout, but still sleep 0.1 seconds after just to be safe
test_connection "$HOST" "$PORT"

result=$?
if [ $result -eq 0 ] ; then
if [ $# -gt 0 ] ; then
Expand Down

0 comments on commit 67a77ef

Please sign in to comment.