From af160ab15635a5c38ec69117d3798e537a286bdb Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Tue, 14 Mar 2023 23:11:42 +0300 Subject: [PATCH] docker-stack: add systemd timer --- machines/modules/docker-stack.nix | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/machines/modules/docker-stack.nix b/machines/modules/docker-stack.nix index f355e44..2608d43 100644 --- a/machines/modules/docker-stack.nix +++ b/machines/modules/docker-stack.nix @@ -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 = {