[Main]
Type = classic
Version = 0.1.0
Description = "watchdog daemon"
User = ( root )
Depends = ( mount-rw )
Options = ( log )

[Start]
Execute = (
	# watchdog in foreground (-F), matching debian/sv/watchdog.
	# Pause unless run_watchdog=1 in /etc/default/watchdog (runit exits 161).
	
	envfile -I /etc/default/watchdog
	importas -uD "0" run_watchdog run_watchdog
	importas -sCuD "" watchdog_options watchdog_options
	importas -uD "none" watchdog_module watchdog_module
	
	ifelse { test "${run_watchdog}" = 1 } {
		foreground {
			ifelse { test "${watchdog_module}" != none } {
				/sbin/modprobe ${watchdog_module}
			}
			exit 0
		}
		# Only one feeder may own /dev/watchdog.
		foreground {
			ifelse { test -x /usr/sbin/wd_keepalive } {
				start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/wd_keepalive.pid --exec /usr/sbin/wd_keepalive
			}
			exit 0
		}
		foreground { rm -f /run/sendsigs.omit.d/wd_keepalive.pid }
		exec /usr/sbin/watchdog ${Args} ${watchdog_options}
	}
	s6-pause
)

[Logger]
RunAs = s6log
Backup = 3
MaxSize = 2000000
Timestamp = tai
Destination = /var/log/watchdog-s6

[Environment]
Args = !-F
