diff --git a/modules/services/dyn-dns.nix b/modules/services/dyn-dns.nix index 84d74a313..851f84049 100644 --- a/modules/services/dyn-dns.nix +++ b/modules/services/dyn-dns.nix @@ -86,7 +86,8 @@ in echo "UPNP changed $oldUpnp -> $newUpnp" fi - exit $(test -f '${cfg.ipPath}' -a '${cfg.upnpPath}') + exit $(test -f '${cfg.ipPath}') + # exit $(test -f '${cfg.ipPath}' -a -f '${cfg.upnpPath}') ''; }; @@ -95,27 +96,33 @@ in timerConfig.OnUnitInactiveSec = cfg.interval; }; - systemd.targets.dyn-dns-valid = { - 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 + systemd.targets.dyn-dns-exists = { + # consumers depend directly on this target for permission to *start* + # once active, this target should never de-activate + description = "initial acquisition of dynamic DNS data"; + wants = [ "dyn-dns.service" ]; after = [ "dyn-dns.service" ]; - requiredBy = cfg.restartOnChange; #< requiredBy will propagate restarts (and explicit stops, but not starts) + wantedBy = cfg.restartOnChange; before = cfg.restartOnChange; }; - 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 ]; + systemd.targets.dyn-dns-events = { + # consumers depend on this to be restarted whenever DNS changes (after acquisition) + description = "event system that notifies via restart whenever dynamic DNS mapping changes"; + requiredBy = cfg.restartOnChange; + # before = cfg.restartOnChange; }; + systemd.paths.dyn-dns-changed = { + wantedBy = cfg.restartOnChange; + wants = [ "dyn-dns-exists.target" ]; + after = [ "dyn-dns-exists.target" ]; + pathConfig.PathChanged = [ cfg.ipPath ]; + }; systemd.services.dyn-dns-changed = { - description = "called when dynamic DNS address changes, to restart all listeners"; + description = "dynamic DNS change notifier"; serviceConfig.Type = "oneshot"; - serviceConfig.ExecStart = "${lib.getExe' pkgs.systemd "systemctl"} restart dyn-dns-valid.target"; + serviceConfig.ExecStart = "${lib.getExe' pkgs.systemd "systemctl"} restart dyn-dns-events.target"; }; }; }