Created
March 20, 2018 12:18
-
-
Save dedeibel/210882aef88812198d16bf789c982018 to your computer and use it in GitHub Desktop.
Waiting for URL to return a propert HTTP response
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
#!/usr/bin/env bash | |
URL="$1" | |
# 10 * (30 + 1) is 310s => ~5m | |
MAX=10 | |
SLEEP_SECONDS=1 | |
IT=0 | |
if [ -z "$URL" ]; then | |
echo "usage $0: URL" | |
exit 1 | |
fi | |
service_ready() { | |
curl --silent --max-time 30 -o /dev/null "${URL}" | |
} | |
echo "checking for service '${URL}'" | |
while !(service_ready); do | |
if [ $IT -gt $MAX ]; then | |
echo "ERROR service did not start after ${IT} polls." | |
exit 1 | |
fi | |
IT=$(($IT+1)) | |
sleep "$SLEEP_SECONDS" | |
echo "checking for service \"${URL}\" (try $IT of $MAX)" | |
done | |
echo "ok" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment