2023-09-29 13:16:09 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Set the endpoint URL
|
|
|
|
endpoint_url=$2
|
|
|
|
name=$1
|
|
|
|
|
|
|
|
# if name or endpoint is not provided, exit
|
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
echo "❌ Error: Please provide a name and endpoint URL"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Set the maximum number of retries
|
|
|
|
max_retries=20 # This allows for 12 attempts, which totals 1 minute with 5 seconds between each retry
|
2024-01-25 11:32:16 +00:00
|
|
|
retry_interval=15 # Retry interval in seconds
|
2023-09-29 13:16:09 +00:00
|
|
|
|
|
|
|
# Initialize variables
|
|
|
|
retries=0
|
|
|
|
http_status=0
|
|
|
|
|
|
|
|
# Loop until either the endpoint returns 200 or the maximum retries are reached
|
|
|
|
while [ $retries -lt $max_retries ]; do
|
2024-06-20 19:24:27 +00:00
|
|
|
# Make a curl request and capture the HTTP status code, following redirects
|
|
|
|
http_status=$(curl -s -o /dev/null -w "%{http_code}" -L $endpoint_url)
|
2023-09-29 13:16:09 +00:00
|
|
|
|
|
|
|
# Check if the HTTP status code is 200 (OK)
|
|
|
|
if [ $http_status -eq 200 ]; then
|
2023-09-29 13:26:09 +00:00
|
|
|
echo "✅ $name endpoint is up ($endpoint_url)"
|
2023-09-29 13:16:09 +00:00
|
|
|
exit 0 # Exit the script with success status
|
|
|
|
else
|
2024-06-09 13:49:48 +00:00
|
|
|
echo "$name $endpoint_url returned HTTP $http_status, retrying in $retry_interval seconds. Usually takes few minutes to boot."
|
2023-09-29 13:16:09 +00:00
|
|
|
sleep $retry_interval
|
|
|
|
retries=$((retries + 1))
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# If the loop exits without getting HTTP 200, throw an error
|
|
|
|
echo "❌ Error: Maximum retries reached, $name still not returning HTTP 200. It could be down or taking longer than expected to start."
|
|
|
|
exit 1 # Exit the script with an error status
|