Skip to content

Commit

Permalink
healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
metachris committed Jun 13, 2024
1 parent 54f65f3 commit 616f030
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions scripts/website-healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash
#
# Check health of relayscan.io and send notifications if state changes
#
set -o errexit
set -o nounset
set -o pipefail

url="https://www.relayscxan.io/healthz"
# url="localhost:9060/healthz"
check_fn="/tmp/relayscan-error.txt"

# load environment variables $PUSHOVER_APP_TOKEN and $PUSHOVER_APP_KEY
source "$(dirname "$0")/../.env.prod"

function send_notification() {
curl -s \
--form-string "token=$PUSHOVER_APP_TOKEN" \
--form-string "user=$PUSHOVER_APP_KEY" \
--form-string "message=$1" \
https://api.pushover.net/1/messages.json
}

function error() {
# prevent sending multiple notifications
if [ -f $check_fn ]; then
return
fi

echo "relayscan.io is unhealthy"
send_notification "relayscan.io is unhealthy"
curl -vvvv $url > $check_fn 2>&1
}

function reset() {
# Don't run if no error
if [ ! -f $check_fn ]; then
return
fi

rm $check_fn
echo "relayscan.io is healthy again"
send_notification "relayscan.io is healthy again"
}

# allow errors, to catch bad curl exit code
set +e
cmd="curl -s $url"
echo $cmd
$cmd
if [ $? -eq 0 ]; then
reset
else
echo "curl error"
error
fi

0 comments on commit 616f030

Please sign in to comment.