add watchdog service

This commit is contained in:
Daniel Barlow 2023-09-02 17:28:40 +01:00
parent 6805e0090d
commit 83092b7b73
5 changed files with 66 additions and 40 deletions

View file

@ -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";
}

23
modules/watchdog/gaspode.sh Executable file
View file

@ -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

View file

@ -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)}";
}