docker-stack: add systemd timer

This commit is contained in:
Dmitriy Pleshevskiy 2023-03-14 23:11:42 +03:00
parent 6f7bf47520
commit af160ab156
Signed by: pleshevskiy
GPG key ID: 79C4487B44403985

View file

@ -168,6 +168,15 @@ let
> $out
'';
mkStackTimer = stackName: {
wantedBy = [ "timers.target" ];
timerConfig = {
OnBootSec = "5m";
OnUnitActiveSec = "5m";
Unit = "docker-stack-${stackName}.service";
};
};
mkStackService = stackName: stack:
let
escapedStackName = lib.escapeShellArg stackName;
@ -175,6 +184,7 @@ let
in
{
description = "Deploy ${escapedStackName} stack";
enable = true;
after = [ "docker.service" "docker.socket" ];
environment = proxyEnv;
@ -200,7 +210,8 @@ in
description = lib.mdDoc "Docker stacks to deploy using systemd services.";
};
config = lib.mkIf (cfg.stacks != { }) {
config = lib.mkIfattrNames (cfg.stacks != { }) {
systemd.timers = lib.mapAttrs' (n: v: lib.nameValuePair "docker-stack-${n}" (mkStackTimer n)) cfg.stacks;
systemd.services = lib.mapAttrs' (n: v: lib.nameValuePair "docker-stack-${n}" (mkStackService n v)) cfg.stacks;
virtualisation.docker = {