Last active
August 19, 2016 05:06
-
-
Save ypereirareis/964cd2d2b608faa371f5 to your computer and use it in GitHub Desktop.
Script to wait for a host to become available locally
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wait_single_host() { | |
local host=$1 | |
shift | |
local port=$1 | |
shift | |
echo "==> Check host ${host}:${port}" | |
while ! nc ${host} ${port} > /dev/null 2>&1 < /dev/null; do echo " --> Waiting for ${host}:${port}" && sleep 1; done; | |
} | |
wait_all_hosts() { | |
if [ ! -z "$WAIT_FOR_HOSTS" ]; then | |
local separator=':' | |
for _HOST in $WAIT_FOR_HOSTS ; do | |
IFS="${separator}" read -ra _HOST_PARTS <<< "$_HOST" | |
wait_single_host "${_HOST_PARTS[0]}" "${_HOST_PARTS[1]}" | |
done | |
else | |
echo "IMPORTANT : Waiting for nothing because no $WAIT_FOR_HOSTS env var defined !!!" | |
fi | |
} | |
wait_all_hosts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment