bundles/pppd: add systemd-timer to automatically update dyndns

This commit is contained in:
Franzi 2021-12-19 06:21:04 +01:00
parent 573287e6f1
commit 5261375574
Signed by: kunsi
GPG key ID: 12E3D2136B818350
4 changed files with 75 additions and 10 deletions

View file

@ -0,0 +1,17 @@
#!/bin/bash
[[ -n "$DEBUG" ]] && set -x
interface="$(ip link show | awk '/ ppp/ {print substr($2, 1, length($2)-1)}')"
addr="$(ip addr show dev "$interface" | awk '/inet / {print $2}')"
resolved="$(dig +short "${domain}" A)"
if [[ -z "$addr" ]] || [[ -z "$resolved" ]]
then
echo "Something is wrong:"
echo "Address on '$interface' is '$addr'"
echo "Resolved DNS is '$resolved'"
elif [[ "$addr" != "$resolved" ]]
then
/etc/ppp/ip-up.d/dyndns "$interface" "doesnt" "matter" "$addr"
fi

View file

@ -0,0 +1,5 @@
[Unit]
Description=dyndns periodic checker and updater
[Service]
ExecStart=/usr/local/bin/dyndns_periodic

View file

@ -0,0 +1,8 @@
[Unit]
Description=run dyndns periodic checker and updater
[Timer]
OnCalendar=*:0/5
[Install]
WantedBy=timers.target

View file

@ -93,6 +93,17 @@ files = {
},
}
svc_systemd = {
'pppoe': {
'needs': {
'file:/etc/ppp/chap-secrets',
'file:/etc/ppp/pap-secrets',
'file:/etc/ppp/peers/provider',
'file:/etc/systemd/system/pppoe.service',
},
},
}
if node.metadata.get('pppd/dyndns', {}):
files['/etc/ppp/ip-up.d/dyndns'] = {
'content_type': 'mako',
@ -104,14 +115,38 @@ if node.metadata.get('pppd/dyndns', {}):
'context': node.metadata.get('pppd/dyndns'),
'mode': '0755',
}
svc_systemd = {
'pppoe': {
'needs': {
'file:/etc/ppp/chap-secrets',
'file:/etc/ppp/pap-secrets',
'file:/etc/ppp/peers/provider',
'file:/etc/systemd/system/pppoe.service',
files['/usr/local/bin/dyndns_periodic'] = {
'content_type': 'mako',
'context': node.metadata.get('pppd/dyndns'),
'mode': '0755',
}
files['/etc/systemd/system/dyndns_periodic.timer'] = {
'triggers': {
'action:systemd-reload',
'svc_systemd:dyndns_periodic.timer:restart',
},
},
}
}
files['/etc/systemd/system/dyndns_periodic.service'] = {
'triggers': {
'action:systemd-reload',
},
}
svc_systemd['dyndns_periodic.timer'] = {
'needs': {
'file:/etc/systemd/system/dyndns_periodic.timer',
'file:/etc/systemd/system/dyndns_periodic.service',
},
}
else:
files['/etc/systemd/system/dyndns_periodic.timer'] = {
'delete': True,
}
files['/etc/systemd/system/dyndns_periodic.service'] = {
'delete': True,
}
svc_systemd['dyndns_periodic.timer'] = {
'before': {
'file:/etc/systemd/system/dyndns_periodic.timer',
'file:/etc/systemd/system/dyndns_periodic.service',
},
}