Sure.
I run my watchdog with a cron-job (crontab) on the ‘root’ user
*/5 * * * * /root/rtlamr_watchdog.sh >/dev/null 2>&1
Here’s the contents of my script for the watchdog (note: requires lsof
utility installed):
#!/bin/bash
#
# This file is designed to monitor for a failure in soundmodem or aprx and restart the process automatically
# Save this file to /root/aprx_watchdog.sh
#
# Crontab entry
# */5 * * * * /root/rtlamr_watchdog.sh >/dev/null 2>&1
# watchdog if rtl_tcp crashes
/bin/systemctl is-active --quiet rtl_tcp || (
/bin/echo 'Service rtl_tcp failed, restarting rtl_tcp and rtlamr . . .' | /usr/bin/wall
/usr/sbin/service rtl_tcp restart
sleep 5
/usr/sbin/service rtl_amr restart
sleep 30
)
# watchdog if rtlamr crashes
/bin/systemctl is-active --quiet rtlamr || (
/bin/echo 'Service rtlamr failed, restarting . . .' | /usr/bin/wall
/usr/sbin/service rtlamr restart
sleep 30
)
# watchdog if rtl_tcp networking fails
/usr/bin/lsof -i | grep rtl_tcp | grep LISTEN > /dev/null || (
/bin/echo 'Network socket rtl_tcp failed, restarting rtl_tcp and rtlamr . . .' | /usr/bin/wall
/usr/sbin/service rtl_tcp restart
sleep 5
/usr/sbin/service rtl_amr restart
sleep 30
)
# watchdog if rtlamr networking fails
/usr/bin/lsof -i | grep rtlamr | grep ESTABLISHED > /dev/null || (
/bin/echo 'Network socket rtlamr failed, restarting . . .' | /usr/bin/wall
/usr/sbin/service rtlamr restart
sleep 30
)
Here is what I used to build the init-startup scripts for rtl_tcp and rtlamr, note you would probably need to tweak what it runs since mine was aimed a PHP script (which writes to my sqlite app, and also throws out over MQTT)
You will want services for both rtl_tcp and rtlamr separately if you use my watchdog as-is. Basically I clone someone else’s template and change some fields…I automated it for rtl_tcp at least.
At this point I don’t have my repository fully updated but that should give you the bits I use.
Hopefully that helps!