diff --git a/bundles/pppd/files/dyndns_periodic b/bundles/pppd/files/dyndns_periodic new file mode 100644 index 0000000..3aebb47 --- /dev/null +++ b/bundles/pppd/files/dyndns_periodic @@ -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 diff --git a/bundles/pppd/files/dyndns_periodic.service b/bundles/pppd/files/dyndns_periodic.service new file mode 100644 index 0000000..9f01ccf --- /dev/null +++ b/bundles/pppd/files/dyndns_periodic.service @@ -0,0 +1,5 @@ +[Unit] +Description=dyndns periodic checker and updater + +[Service] +ExecStart=/usr/local/bin/dyndns_periodic diff --git a/bundles/pppd/files/dyndns_periodic.timer b/bundles/pppd/files/dyndns_periodic.timer new file mode 100644 index 0000000..5e4fb47 --- /dev/null +++ b/bundles/pppd/files/dyndns_periodic.timer @@ -0,0 +1,8 @@ +[Unit] +Description=run dyndns periodic checker and updater + +[Timer] +OnCalendar=*:0/5 + +[Install] +WantedBy=timers.target diff --git a/bundles/pppd/items.py b/bundles/pppd/items.py index c908449..8d94950 100644 --- a/bundles/pppd/items.py +++ b/bundles/pppd/items.py @@ -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', + }, + }