Skip to content

Instantly share code, notes, and snippets.

@Gameghostify
Created January 20, 2020 16:57
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 Gameghostify/8cc9eb93d0ef0cdc9bf66aa97ab15049 to your computer and use it in GitHub Desktop.
Save Gameghostify/8cc9eb93d0ef0cdc9bf66aa97ab15049 to your computer and use it in GitHub Desktop.
Wait until a web service is up and accepts connections
#!/bin/sh
### not needed
echo "$(tput setaf 3)waiting for api service to accept connections$(tput sgr0)"
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
###
api_service_url="http://localhost:8080" # FIXME enter correct url
attempt_counter=0
max_attempts=20
until [ $(curl -s -o /dev/null -w "%{http_code}" $api_service_url) -ne 000 ]; do
if [ ${attempt_counter} -eq ${max_attempts} ];then
echo "Unable to ping api service, aborting"
exit 1
fi
printf '.'
attempt_counter=$(($attempt_counter+1))
sleep 3
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment