Created
May 14, 2018 10:24
-
-
Save rockotseng/28fa7fe3244ce9fdcb690231eea1d95b to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
set -e | |
hostport=(${1//:/ }) | |
host=${hostport[0]} | |
port=${hostport[1]} | |
shift | |
cmd="$@" | |
if [[ "$host" == "" || "$port" == "" ]]; then | |
echo "Usage: $0 host:port cmd" | |
exit 1 | |
fi | |
while ! nc -z $host $port; do | |
>&2 echo "Service is unavailable - sleeping" | |
sleep 1 | |
done | |
>&2 echo "Service is up - executing command" | |
exec $cmd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment