#!/usr/bin/env /lib/runit/invoke-run
#Copyright: 2026 Aitor <aitor@genuen.org>
#License: CC0-1.0
#Comment: ported for runit-services testing (watchdog)

exec 2>&1
run_watchdog=0
watchdog_options=""
watchdog_module="none"
[ -e /etc/default/watchdog ] && . /etc/default/watchdog
[ "$run_watchdog" = 1 ] || exit 161
[ -x /usr/sbin/watchdog ] || exit 162
[ "${watchdog_module:-none}" != "none" ] && /sbin/modprobe "$watchdog_module" || true
# Stop keepalive if present so only one feeder owns the device
if [ -x /usr/sbin/wd_keepalive ]; then
  start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/wd_keepalive.pid \
    --exec /usr/sbin/wd_keepalive 2>/dev/null || true
  rm -f /run/sendsigs.omit.d/wd_keepalive.pid
fi
exec /usr/sbin/watchdog -F $watchdog_options
