Skip to content

Instantly share code, notes, and snippets.

@0x5e
Created March 29, 2023 05:54
Show Gist options
  • Save 0x5e/13508ac931c1ad0329066e13c50b265d to your computer and use it in GitHub Desktop.
Save 0x5e/13508ac931c1ad0329066e13c50b265d to your computer and use it in GitHub Desktop.
OpenWrt DDNS service watchdog. Auto restart service when it exited unexpectedly.
#!/bin/sh
# Run this script from cron every 10 minutes:
# echo '*/10 * * * * /path/to/ddns_watchdog.sh' >> /etc/crontabs/root
. /lib/functions.sh
handle_ddns_service() {
local cfg="$1"
local enabled
config_get enabled "${cfg}" enabled
[ $enabled != "1" ] && return 0;
pid=`cat /tmp/run/ddns/$cfg.pid`
[ -n "$(ps | awk '{print $1}' | grep $pid)" ] && return 0;
logger -t "ddns_monitor" "service $cfg not running. launching..."
/bin/sh /usr/lib/ddns/dynamic_dns_updater.sh -v 0 -S $cfg -- start &
}
config_load ddns
config_foreach handle_ddns_service service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment