feat(systemdNotify): limit to one invocation every 15 minutes per service
All checks were successful
Test / tests (push) Successful in 4m5s

Also adds an `ExecCondition` for ignoring service auto-resarts.
This commit is contained in:
Felix Schröter 2025-09-23 22:15:57 +02:00
parent c8e0b67ed4
commit 9690a9de0f
Signed by: felschr
GPG key ID: 671E39E6744C807D

View file

@ -26,6 +26,16 @@ let
$(systemctl status --full "$1")
ERRMAIL
'';
checkConditions = pkgs.writeScript "check-conditions" ''
#!/bin/sh
STATUS=$(systemctl status --full "$1")
case "$STATUS" in
*"activating (auto-restart) (Result: timeout)"*) exit 1 ;;
*) exit 0 ;;
esac
'';
in
{
options = {
@ -85,10 +95,21 @@ in
}
];
systemd.services."notify@" = {
systemd.services."notify@" =
lib.recursiveUpdate
{
onFailure = lib.mkForce [ ];
unitConfig = {
StartLimitIntervalSec = "15m";
StartLimitBurst = 1;
};
serviceConfig = {
Type = "oneshot";
ExecCondition = "${checkConditions} %i";
};
}
// optionalAttrs (cfg.method == "libnotify") {
(
optionalAttrs (cfg.method == "libnotify") {
description = "Desktop notifications for %i service failure";
environment = {
DISPLAY = ":0";
@ -100,17 +121,12 @@ in
"Service '$INSTANCE' failed" \
"$(journalctl -n 6 -o cat -u $INSTANCE)"
'';
serviceConfig = {
Type = "oneshot";
User = cfg.libnotify.user;
};
serviceConfig.User = cfg.libnotify.user;
}
// optionalAttrs (cfg.method == "email") {
description = "E-Mail notifications for %i service failure";
serviceConfig = {
ExecStart = "${sendmail} %i";
Type = "oneshot";
};
};
serviceConfig.ExecStart = "${sendmail} %i";
}
);
};
}