Configuration
Create an account at
healthchecks.io.
Once done, you can name the default check you see there. It will have a url having https://hc-ping.com/uuid.
Now we just need to make the RPi ping this address at a time interval comfortable to us.
Now we need to create a shell script to ping hte address, and a service to start this script. And we also need to create a timer for this service.
The contents of the shell script - hc_heartbeat.sh:
#!/bin/bash
URL="https://hc-ping.com/uuid"
# Send heartbeat
curl -m 10 --retry 5 "$URL" >/dev/null
Now we need to run this script using a service. The contents of this service - /etc/systemd/system/healthcheck.service:
[Unit]
Description=Healthchecks Heartbeat Service
[Service]
Type=oneshot
ExecStart=/home/piserver/Desktop/hc_heartbeat.sh
Now we need to set a timer for this script. The contents of this timer - /etc/systemd/system/healthcheck.timer:
[Unit]
Description=Run Healthchecks Heartbeat every 30 seconds
[Timer]
Unit=healthcheck.service
OnBootSec=15
OnUnitActiveSec=60
[Install]
WantedBy=timers.target
To enable the timer, use these below commands:
sudo systemctl daemon-reload
sudo systemctl enable healthcheck.timer && sudo systemctl start healthcheck.timer
Everything is setup on the Pi now. You need to edit the check in healthchecks.io now.
I set the Schedule Period and Grace Time to 1 minute. Now we will be alerted if we miss ping within 2 minutes.
You can set the password for the account to make it more secure than getting a link to the email address.
Service Checks
I am hosting two services on zrok right now. Owncloud (filebrowser) and Ownflix (jellyfin).
Autostar and many other startup techniques frequently failed to start up.
So, what if I checked if the site is up using curl? If it is not, then I can start the startup script the runs these services.
if curl -fsS --max-time 10 --retry 5 -D - -o /dev/null "https://ownflix.share.zrok.io"; then
echo "$(date) - URL is UP"
else
echo "$(date) - zrok is DOWN, running the startup script" >> /home/piserver/testrunning.log 2>&1
/home/piserver/startup.sh
fi
By adding logging for a failed curl, we can log when the script is being started.