WIP: dyn-dns: try a smarter trigger scheme, but im getting weird "resource" errors with systemd path units
This commit is contained in:
@@ -57,6 +57,9 @@ in
|
||||
|
||||
after = [ "network.target" ];
|
||||
|
||||
serviceConfig.Restart = "on-failure";
|
||||
serviceConfig.RestartSec = "60s";
|
||||
|
||||
script = let
|
||||
jq = lib.getExe pkgs.jq;
|
||||
sed = lib.getExe pkgs.gnused;
|
||||
@@ -88,27 +91,31 @@ in
|
||||
};
|
||||
|
||||
systemd.timers.dyn-dns = {
|
||||
wants = [ "dyn-dns.service" ]; #< start the service immediately
|
||||
timerConfig.OnUnitActiveSec = cfg.interval;
|
||||
wantedBy = [ "dyn-dns.service" ];
|
||||
timerConfig.OnUnitInactiveSec = cfg.interval;
|
||||
};
|
||||
|
||||
systemd.paths.dyn-dns-watcher = {
|
||||
wantedBy = cfg.restartOnChange;
|
||||
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
|
||||
after = [ "dyn-dns.service" ];
|
||||
requiredBy = cfg.restartOnChange; #< requiredBy will propagate restarts (and explicit stops, but not starts)
|
||||
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 ];
|
||||
};
|
||||
|
||||
systemd.targets.dyn-dns-reactor = {
|
||||
description = "react to the system's WAN IP changing";
|
||||
# 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;
|
||||
systemd.services.dyn-dns-changed = {
|
||||
description = "called when dynamic DNS address changes, to restart all listeners";
|
||||
serviceConfig.Type = "oneshot";
|
||||
serviceConfig.ExecStart = "${lib.getExe' pkgs.systemd "systemctl"} restart dyn-dns-valid.target";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user