commit 83092b7b734b2d90c22910b57d5b7f62110c7675
parent 6805e0090d58330d4a7277a66034b032b5462d12
Author: Daniel Barlow <dan@telent.net>
Date: Sat, 2 Sep 2023 17:28:40 +0100
add watchdog service
Diffstat:
5 files changed, 66 insertions(+), 40 deletions(-)
diff --git a/devices/gl-mt300n-v2/default.nix b/devices/gl-mt300n-v2/default.nix
@@ -146,10 +146,6 @@
NET_RALINK_SOC="y";
SWPHY = "y";
- WATCHDOG = "y";
- RALINK_WDT = "y"; # watchdog
- MT7621_WDT = "y"; # or it might be this one
-
GPIOLIB="y";
GPIO_MT7621 = "y";
@@ -162,6 +158,9 @@
PRINTK_TIME = "y";
} // lib.optionalAttrs (config.system.service ? vlan) {
SWCONFIG = "y";
+ } // lib.optionalAttrs (config.system.service ? watchdog) {
+ RALINK_WDT = "y"; # watchdog
+ MT7621_WDT = "y"; # or it might be this one
};
};
};
diff --git a/examples/arhcive.nix b/examples/arhcive.nix
@@ -29,6 +29,7 @@ in rec {
../modules/network
../modules/vlan
../modules/ssh
+ ../modules/watchdog
];
hostname = "arhcive";
@@ -67,42 +68,9 @@ in rec {
services.sshd = svc.ssh.build { };
- 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.watchdog = svc.watchdog.build {
+ watched = with config.services ; [ sshd dhcpc ];
+ };
services.resolvconf = oneshot rec {
dependencies = [ services.dhcpc ];
diff --git a/modules/watchdog/default.nix b/modules/watchdog/default.nix
@@ -0,0 +1,24 @@
+{ lib, pkgs, config, ...}:
+let
+ inherit (lib) mkOption types;
+ inherit (pkgs) liminix;
+in
+{
+ options = {
+ system.service.watchdog = mkOption {
+ type = liminix.lib.types.serviceDefn;
+ };
+ };
+ config.system.service.watchdog = liminix.callService ./watchdog.nix {
+ watched = mkOption {
+ description = "services to watch";
+ type = types.listOf liminix.lib.types.service;
+ };
+ headStart = mkOption {
+ description = "delay in seconds before watchdog starts checking service health";
+ default = 60;
+ type = types.int;
+ };
+ };
+ config.kernel.config.WATCHDOG = "y";
+}
diff --git a/modules/watchdog/gaspode.sh b/modules/watchdog/gaspode.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+deadline=$(expr $(date +%s) + ${HEADSTART})
+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
diff --git a/modules/watchdog/watchdog.nix b/modules/watchdog/watchdog.nix
@@ -0,0 +1,12 @@
+{
+ liminix
+, lib
+}:
+{ watched, headStart } :
+let
+ inherit (liminix.services) longrun;
+in longrun {
+ name = "watchdog";
+ run =
+ "HEADSTART=${toString headStart} ${./gaspode.sh} ${lib.concatStringsSep " " (builtins.map (s: s.name) watched)}";
+}