dyn-dns: fix to only react when the IP actually changes

This commit is contained in:
colin 2022-12-19 11:54:27 +00:00
parent 0b2faef989
commit 3122334a41

View File

@ -45,8 +45,14 @@ in
restartTriggers = [(builtins.toJSON cfg)];
serviceConfig.Type = "oneshot";
script = ''
mkdir -p $(dirname "${cfg.ipPath}")
${cfg.ipCmd} > "${cfg.ipPath}"
mkdir -p $(dirname '${cfg.ipPath}')
newIp=$(${cfg.ipCmd})
# systemd path units are triggered on any file write action,
# regardless of content change. so only update the file if our IP *actually* changed
if [ "$newIp" != "$(cat '${cfg.ipPath}')" ]
then
echo "$newIp" > '${cfg.ipPath}'
fi
'';
};