dyn-dns: when DNS changes, restart immediately instead of blocking on another dyn-dns.service query

the new behavior though causes dyn-dns consumers to be started even before we've learned the IP. that sort of matches the semantics of the module though. not sure the best design yet
This commit is contained in:
2024-11-11 23:41:58 +00:00
parent 388c58f656
commit 5aa6c9b8c7

View File

@@ -56,8 +56,6 @@ in
restartTriggers = [(builtins.toJSON cfg)];
after = [ "network.target" ];
wantedBy = cfg.restartOnChange;
before = cfg.restartOnChange;
script = let
jq = lib.getExe pkgs.jq;
@@ -90,28 +88,27 @@ in
};
systemd.timers.dyn-dns = {
# if anything wants dyn-dns.service, they surely want the timer too.
wantedBy = [ "dyn-dns.service" ];
timerConfig = {
OnUnitActiveSec = cfg.interval;
};
wants = [ "dyn-dns.service" ]; #< start the service immediately
timerConfig.OnUnitActiveSec = cfg.interval;
};
systemd.paths.dyn-dns-watcher = {
before = [ "dyn-dns.timer" ];
wantedBy = [ "dyn-dns.timer" ];
pathConfig = {
Unit = "dyn-dns-reactor.service";
PathChanged = [ cfg.ipPath ];
};
wantedBy = cfg.restartOnChange;
before = cfg.restartOnChange;
wants = [ "dyn-dns.timer" ];
pathConfig.Unit = "dyn-dns-reactor.target";
pathConfig.PathChanged = [ cfg.ipPath ];
};
systemd.services.dyn-dns-reactor = {
systemd.targets.dyn-dns-reactor = {
description = "react to the system's WAN IP changing";
serviceConfig.Type = "oneshot";
script = if cfg.restartOnChange != [] then ''
${lib.getExe' pkgs.systemd "systemctl"} restart ${toString cfg.restartOnChange}
'' else lib.getExe' pkgs.coreutils "true";
# when started, have systemd `stop` the services we want to restart:
unitConfig.Conflicts = cfg.restartOnChange;
after = cfg.restartOnChange;
# then, have systemd stop *this* unit
unitConfig.StopWhenUnneeded = true;
# and as this unit enters the inactive state, it can start the services:
unitConfig.OnSuccess = cfg.restartOnChange;
};
};
}