mirror of
https://github.com/SebastianStork/nixos-config.git
synced 2026-01-21 17:31:34 +01:00
Add fail trigger to backup healthchecks
This commit is contained in:
parent
8ab39c79ab
commit
b14db2b903
1 changed files with 22 additions and 15 deletions
|
|
@ -33,13 +33,13 @@ in
|
|||
name: value: "d /var/cache/restic-backups-${name} 700 ${value.user} ${value.user} -"
|
||||
) cfg;
|
||||
|
||||
users.groups.restic.members = lib.mapAttrsToList (_: value: value.user) cfg;
|
||||
users.groups.backup.members = lib.mapAttrsToList (_: value: value.user) cfg;
|
||||
|
||||
sops.secrets =
|
||||
let
|
||||
resticPermissions = {
|
||||
mode = "440";
|
||||
group = config.users.groups.restic.name;
|
||||
group = config.users.groups.backup.name;
|
||||
};
|
||||
in
|
||||
{
|
||||
|
|
@ -69,21 +69,28 @@ in
|
|||
// value.extraConfig
|
||||
) cfg;
|
||||
|
||||
systemd.services = lib.mapAttrs' (
|
||||
systemd.services = lib.mkMerge [
|
||||
(lib.mapAttrs' (
|
||||
name: _:
|
||||
lib.nameValuePair "restic-backups-${name}" (
|
||||
let
|
||||
ping = signal: ''
|
||||
lib.nameValuePair "restic-backups-${name}" {
|
||||
wants = [ "healthcheck-ping@${name}-backup_start.service" ];
|
||||
onSuccess = [ "healthcheck-ping@${name}-backup.service" ];
|
||||
onFailure = [ "healthcheck-ping@${name}-backup_fail.service" ];
|
||||
}
|
||||
) (lib.filterAttrs (_: value: value.healthchecks.enable) cfg))
|
||||
|
||||
(lib.mkIf ((lib.filterAttrs (_: value: value.healthchecks.enable) cfg) != { }) {
|
||||
"healthcheck-ping@" = {
|
||||
description = "Pings healthcheck (%i)";
|
||||
serviceConfig.Type = "oneshot";
|
||||
scriptArgs = "%i";
|
||||
script = ''
|
||||
${lib.getExe pkgs.curl} -fsS -m 10 --retry 5 https://hc-ping.com/$(cat ${
|
||||
config.sops.secrets."healthchecks-ping-key".path
|
||||
})/${name}-backup/${signal}
|
||||
})/$(echo $1 | tr _ /)
|
||||
'';
|
||||
in
|
||||
{
|
||||
preStart = lib.mkBefore (ping "start");
|
||||
postStop = lib.mkAfter (ping "0");
|
||||
}
|
||||
)
|
||||
) (lib.filterAttrs (_: value: value.healthchecks.enable) cfg);
|
||||
};
|
||||
})
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue