feat(nix): enhance systemd-email-notify service configuration
- Added `StartLimitIntervalSec` and `StartLimitBurst` for `ntfy-failure@` unit. - Refactored `ExecStart` into `script` for improved readability. - Adjusted `scriptArgs` from `%I` to `%i`.
This commit is contained in:
parent
e9bce3fd6a
commit
bcdaa091eb
1 changed files with 20 additions and 15 deletions
|
|
@ -33,8 +33,9 @@ let
|
|||
ERRMAIL
|
||||
'';
|
||||
|
||||
onFailureUnits =
|
||||
[ "email@%n.service" ]
|
||||
onFailureUnits = [
|
||||
"email@%n.service"
|
||||
]
|
||||
++ optionals (cfg.ntfy.tokenFile != null) [ "ntfy-failure@%n.service" ];
|
||||
in
|
||||
{
|
||||
|
|
@ -103,9 +104,14 @@ in
|
|||
systemd.services."ntfy-failure@" = {
|
||||
description = "Send ntfy notification on service failure";
|
||||
onFailure = mkForce [ ];
|
||||
unitConfig = {
|
||||
StartLimitIntervalSec = "5m";
|
||||
StartLimitBurst = 1;
|
||||
};
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
ExecStart = pkgs.writeShellScript "ntfy-failure-notify" ''
|
||||
};
|
||||
script = ''
|
||||
TOKEN=$(cat ${cfg.ntfy.tokenFile})
|
||||
UNIT="$1"
|
||||
${pkgs.curl}/bin/curl -s \
|
||||
|
|
@ -116,8 +122,7 @@ in
|
|||
-d "$(systemctl status --full "$UNIT" 2>&1 | head -40)" \
|
||||
${cfg.ntfy.url}/${cfg.ntfy.topic}
|
||||
'';
|
||||
};
|
||||
scriptArgs = "%I";
|
||||
scriptArgs = "%i";
|
||||
};
|
||||
})
|
||||
]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue