Files
Phx-Yuri/health_check.sh
2024-05-12 07:39:55 +00:00

28 lines
857 B
Bash
Executable File

#!/bin/bash
# Define the URL of your health endpoint
HEALTH_ENDPOINT="http://localhost:3000/health"
# Make a GET request to the health endpoint and capture the response
RESPONSE=$(wget -qO- --timeout=2 "$HEALTH_ENDPOINT" )
# Display the response from the health endpoint
echo "Response from health endpoint: $RESPONSE"
# Extract the value of the "status" field using jq
status=$(echo "$RESPONSE" | jq -r '.status')
# Check if the status is "ok"
if [[ "$status" == "ok" ]]; then
echo "Health check successful"
exit 0 # Exit with success status
else
echo "Health check failed"
exit 1 # Exit with failure status
fi
# if [[ "$RESPONSE" =~ '"status": "ok"' ]]; then
# echo "Health check successful"
# exit 0 # Exit with success status
# else
# echo "Health check failed: $RESPONSE"
# exit 1 # Exit with failure status
# fi