From de9134144b456104953c2533debb27a02787891f Mon Sep 17 00:00:00 2001 From: pacien Date: Sat, 23 Dec 2023 19:13:09 +0100 Subject: [PATCH] unison: better retry/restart reporting failures The service was never marked with a failed state with the previous approach, which could lead broken synchronisation pair states to go undetected. The module now uses a timer instead of unlimited restarts, which does not have this issue. --- modules/services/unison.nix | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/modules/services/unison.nix b/modules/services/unison.nix index d3f0a8e6..452360a6 100644 --- a/modules/services/unison.nix +++ b/modules/services/unison.nix @@ -65,9 +65,10 @@ let serialiseArgs = args: concatStringsSep " " (mapAttrsToList serialiseArg args); + unitName = name: "unison-pair-${name}"; + makeDefs = gen: - mapAttrs' - (name: pairCfg: nameValuePair "unison-pair-${name}" (gen name pairCfg)) + mapAttrs' (name: pairCfg: nameValuePair (unitName name) (gen name pairCfg)) cfg.pairs; in { @@ -106,19 +107,10 @@ in { ]; systemd.user.services = makeDefs (name: pairCfg: { - Unit = { - Description = "Unison pair sync (${name})"; - # Retry forever, useful in case of network disruption. - StartLimitIntervalSec = 0; - }; - + Unit.Description = "Unison pair sync (${name})"; Service = { - Restart = "always"; - RestartSec = 60; - CPUSchedulingPolicy = "idle"; IOSchedulingClass = "idle"; - Environment = [ "UNISON='${toString pairCfg.stateDirectory}'" ]; ExecStart = '' ${cfg.package}/bin/unison \ @@ -126,8 +118,16 @@ in { ${strings.concatMapStringsSep " " escapeShellArg pairCfg.roots} ''; }; + }); - Install = { WantedBy = [ "default.target" ]; }; + systemd.user.timers = makeDefs (name: pairCfg: { + Unit.Description = "Unison pair sync auto-restart (${name})"; + Install.WantedBy = [ "timers.target" ]; + Timer = { + Unit = "${unitName name}.service"; + OnActiveSec = 1; + OnUnitInactiveSec = 60; + }; }); }; }