WIP: dyn-dns: try a smarter trigger scheme, but im getting weird "resource" errors with systemd path units

This commit is contained in:
2024-11-12 01:09:23 +00:00
parent 5aa6c9b8c7
commit 2134a9c738

View File

@@ -57,6 +57,9 @@ in
after = [ "network.target" ]; after = [ "network.target" ];
serviceConfig.Restart = "on-failure";
serviceConfig.RestartSec = "60s";
script = let script = let
jq = lib.getExe pkgs.jq; jq = lib.getExe pkgs.jq;
sed = lib.getExe pkgs.gnused; sed = lib.getExe pkgs.gnused;
@@ -88,27 +91,31 @@ in
}; };
systemd.timers.dyn-dns = { systemd.timers.dyn-dns = {
wants = [ "dyn-dns.service" ]; #< start the service immediately wantedBy = [ "dyn-dns.service" ];
timerConfig.OnUnitActiveSec = cfg.interval; timerConfig.OnUnitInactiveSec = cfg.interval;
}; };
systemd.paths.dyn-dns-watcher = { systemd.targets.dyn-dns-valid = {
wantedBy = cfg.restartOnChange; description = "active while dyn dns data exists, and is restarted whenever dyn dns data changes";
wants = [ "dyn-dns.service" ]; #< restarts of this unit *shouldn't* be propagated to dyn-dns.service
after = [ "dyn-dns.service" ];
requiredBy = cfg.restartOnChange; #< requiredBy will propagate restarts (and explicit stops, but not starts)
before = cfg.restartOnChange; before = cfg.restartOnChange;
wants = [ "dyn-dns.timer" ]; };
pathConfig.Unit = "dyn-dns-reactor.target";
systemd.paths.dyn-dns-changed = {
description = "react to new dynamic DNS data, and if the address changed then propagate that out";
wants = [ "dyn-dns.service" ];
after = [ "dyn-dns.service" ];
wantedBy = [ "dyn-dns-valid.target" ];
before = [ "dyn-dns-valid.target" ];
pathConfig.PathChanged = [ cfg.ipPath ]; pathConfig.PathChanged = [ cfg.ipPath ];
}; };
systemd.targets.dyn-dns-reactor = { systemd.services.dyn-dns-changed = {
description = "react to the system's WAN IP changing"; description = "called when dynamic DNS address changes, to restart all listeners";
# when started, have systemd `stop` the services we want to restart: serviceConfig.Type = "oneshot";
unitConfig.Conflicts = cfg.restartOnChange; serviceConfig.ExecStart = "${lib.getExe' pkgs.systemd "systemctl"} restart dyn-dns-valid.target";
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;
}; };
}; };
} }