Skip to content

Instantly share code, notes, and snippets.

@dedeibel
Created March 20, 2018 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dedeibel/210882aef88812198d16bf789c982018 to your computer and use it in GitHub Desktop.
Save dedeibel/210882aef88812198d16bf789c982018 to your computer and use it in GitHub Desktop.
Waiting for URL to return a propert HTTP response
#!/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