From beb6e260d4e071408026bf86f90afd7bb6493d3c Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Thu, 23 Mar 2023 12:48:10 +0000 Subject: [PATCH] PoC support for hardware watchdog --- devices/gl-ar750/default.nix | 4 ++++ examples/arhcive.nix | 38 ++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/devices/gl-ar750/default.nix b/devices/gl-ar750/default.nix index f7d2272..9e4b2b6 100644 --- a/devices/gl-ar750/default.nix +++ b/devices/gl-ar750/default.nix @@ -186,6 +186,10 @@ MTD = "y"; MTD_CMDLINE_PARTS = "y"; MTD_BLOCK = "y"; # fix undefined ref to register_mtd_blktrans_devs + + WATCHDOG = "y"; + ATH79_WDT = "y"; # watchdog timer + CPU_BIG_ENDIAN= "y"; # this is all copied from nixwrt ath79 config. Clearly not all diff --git a/examples/arhcive.nix b/examples/arhcive.nix index d44f93a..0550848 100644 --- a/examples/arhcive.nix +++ b/examples/arhcive.nix @@ -78,6 +78,43 @@ in rec { ''; }; + services.watchdog = + let + watched = with config.services ; [ sshd dhcpc ]; + spinupGrace = 60; + script = pkgs.writeAshScript "gaspode" { + runtimeInputs = [ pkgs.s6 ]; + } '' + deadline=$(expr $(date +%s) + ${toString spinupGrace}) + services=$@ + echo started feeding the dog + exec 3> ''${WATCHDOG-/dev/watchdog} + + healthy(){ + test $(date +%s) -le $deadline && return 0 + + for i in $services; do + if test "$(s6-svstat -o up /run/service/$i)" != "true" ; then + echo "service $i is down" + return 1 + fi + done + } + + while healthy ;do + sleep 10 + echo >&3 + done + echo "stopped feeding the dog" + sleep 6000 # don't want s6-rc to restart + ''; + in longrun { + name = "watchdog"; + run = + "${script} ${lib.concatStringsSep " " (builtins.map (s: s.name) watched)}"; + }; + + services.resolvconf = oneshot rec { dependencies = [ services.dhcpc ]; name = "resolvconf"; @@ -174,6 +211,7 @@ in rec { resolvconf sshd rsync + watchdog ]; }; users.root.passwd = lib.mkForce secrets.root_password;