Intro
Every few weeks I wake up to none of my hosted services working, despite my server being on and no crashes reported. I found out that HAProxy is the culprit as it seemed to randomly stop running. I checked my configuration and the logs, but nothing seems out of the ordinary.
While I find a proper solution, I created a cron task that acts as a watchdog and restarts HAProxy if the service is stopped.
My setup is:
- pfSense 2.7.2
- HAProxy-devel 0.63_2
HAProxy watchdog script
Create the file /usr/local/sbin/haproxy-watchdog.sh and paste the following contents in there.
#!/bin/sh
service haproxy onestatus >/dev/null 2>&1
status=$?
# If the exit code is not 0, it means HAProxy is not running
if [ "$status" -ne 0 ]; then
service haproxy onestart >/dev/null 2>&1
fiAfterwards give it the appropriate permissions by issuing the command chmod +x /usr/local/sbin/haproxy-watchdog.sh.
Adding the script to the cron service
Ensure the cron package is installed. Navigate to Services->Cron and click on Add. Set the settings as shown in the cover picture at the top of this page.
To test if this is working, stop HAProxy, wait a minute or two, and verify that HAProxy has been restarted.
Done!
Next time HAProxy crashes, this will ensure it gets restarted without manual interference.
