Skip to content

Instantly share code, notes, and snippets.

@tallesairan
Created March 10, 2023 15:49
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 tallesairan/f16b4b9380c8cddc61308a386812f726 to your computer and use it in GitHub Desktop.
Save tallesairan/f16b4b9380c8cddc61308a386812f726 to your computer and use it in GitHub Desktop.
Elasticsearch & Nginx Reverse proxy heartbeat
#!/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