Skip to content

Instantly share code, notes, and snippets.

@LeeCheneler
Last active January 12, 2022 14:05
Show Gist options
  • Save LeeCheneler/d4f20a272f95b16d5118a35853f35973 to your computer and use it in GitHub Desktop.
Save LeeCheneler/d4f20a272f95b16d5118a35853f35973 to your computer and use it in GitHub Desktop.
Wait for server to respond, useful in pipeline to wait for service or app to start
#!/bin/sh
START=$(date '+%s')
TIMEOUT=$(($START + 30))
echo "Waiting for server $1 to start..."
until $(curl --output /dev/null --silent --head --insecure $1); do
NOW=$(date '+%s')
if [ "$NOW" -gt "$TIMEOUT" ]; then
echo "Server $1 failed to start in 30 seconds"
exit 1
fi
sleep 1
done
echo "Server $1 started"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment