Created
March 10, 2023 15:49
-
-
Save tallesairan/f16b4b9380c8cddc61308a386812f726 to your computer and use it in GitHub Desktop.
Elasticsearch & Nginx Reverse proxy heartbeat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Your heartbeat URL here (must be hosted on this server) | |
URL_TO_CHECK="http://ngb1.ahvideoscdn.net" | |
# Your temp file to monitor downtime | |
DOWN_FILE="/root/site_down"; | |
# How long will you tolerate downtime in minutes | |
DOWN_TIME="+0"; | |
HTTP_STATUS=`curl -s -o /dev/null -w "%{http_code}" "$URL_TO_CHECK"`; | |
SITE_DOWN_TOGGLE=`find "$DOWN_FILE"`; | |
echo "$SITE_DOWN_TOGGLE"; | |
if [ "$HTTP_STATUS" != "200" ]; then | |
echo "Website is down $HTTP_STATUS"; | |
if [ "$SITE_DOWN_TOGGLE" != "$DOWN_FILE" ]; then | |
touch "$DOWN_FILE"; | |
echo "Made file $DOWN_FILE"; | |
fi | |
SITE_DOWN_PAST_TIME=`find "$DOWN_FILE" -mmin "$DOWN_TIME"`; | |
if [ "$SITE_DOWN_PAST_TIME" = "$DOWN_FILE" ]; then | |
rm "$DOWN_FILE"; | |
echo "Endpoint down past timecheck... rebooting elasticsearch & nginx"; | |
/usr/bin/systemctl stop nginx | |
/usr/bin/systemctl restart elasticsearch | |
sleep 30 | |
/usr/bin/systemctl start nginx | |
else | |
echo "Site not yet down past $DOWN_TIME tolerance"; | |
fi | |
else | |
rm "$DOWN_FILE"; | |
echo "Website is running $HTTP_STATUS"; | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment