From 7f6334f74301616f9ddae5661937696a8fa5ae7f Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Sat, 23 Nov 2024 15:53:04 +0100 Subject: [PATCH] Fix deployment scripts. --- deployment/primary-dnsmanagerd-to-powerdns.sh | 41 +++++++++++++++++++ deployment/primary-watchdog.sh | 4 +- deployment/secondary-watchdog.sh | 4 +- 3 files changed, 45 insertions(+), 4 deletions(-) create mode 100755 deployment/primary-dnsmanagerd-to-powerdns.sh diff --git a/deployment/primary-dnsmanagerd-to-powerdns.sh b/deployment/primary-dnsmanagerd-to-powerdns.sh new file mode 100755 index 0000000..ad0c271 --- /dev/null +++ b/deployment/primary-dnsmanagerd-to-powerdns.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +# Copying files from the dnsmanagerd bind9 directory to the powerdns directory. +PDNSDIR="/var/powerdns/" +DNSMANDIR="/tmp/DATA-dnsmanagerd/bind9-zones/" + +local_update() { + echo "update domain $1" + # Simulate what is done with dnsmanagerd to avoir file corruption. + cp $DNSMANDIR/$1 $PDNSDIR/$1.wip + mv $PDNSDIR/$1.wip $PDNSDIR/$1 +} + +local_delete() { echo "delete domain $1" ; rm $PDNSDIR/$1 ; } + +action() { + event=$1 + file=$2 + + echo $event | grep "MOVED_TO" >/dev/null + if [ $? -eq 0 ]; then + local_update $file + fi + + echo $event | grep "DELETE" >/dev/null + if [ $? -eq 0 ]; then + local_delete $file + fi +} + +# NOTE: dnsmanagerd writes bind9 files in $DNSMANDIR and with a suffix ".wip" then moves them +# to remove the suffix. This way, the final file is expected to never be corrupted, +# for example by copying it to the secondary DNS server while the zone not being +# fully written to the file. +# +# Therefore, the different interesting actions we should monitor are: +# - moved_to: a zone file has been modified +# - delete: a domain has been removed +opts="-e moved_to -e delete -m" +echo "inotifywait ${opts} --format '%:e %f' $DNSMANDIR" +inotifywait ${opts} --format '%:e %f' $DNSMANDIR | while read FILE; do action $FILE ; done diff --git a/deployment/primary-watchdog.sh b/deployment/primary-watchdog.sh index 7f6d1a6..6ae3c00 100755 --- a/deployment/primary-watchdog.sh +++ b/deployment/primary-watchdog.sh @@ -10,10 +10,10 @@ echo "directory: $DIR" local_update() { echo "local update of domain $1" - pdns_control bind-reload-now $1 + pdns_control bind-reload-now $1 | grep "no such domain" # In case the update cannot be done, it might be because the zone wasn't loaded at all. - if [ $? -ne 0 ]; then + if [ $? -eq 0 ]; then pdns_control bind-add-zone $1 $DIR/$1 fi } diff --git a/deployment/secondary-watchdog.sh b/deployment/secondary-watchdog.sh index 10b2d12..adc4fa6 100755 --- a/deployment/secondary-watchdog.sh +++ b/deployment/secondary-watchdog.sh @@ -5,10 +5,10 @@ DIR="/var/powerdns/" local_update() { echo "update domain $1" - pdns_control bind-reload-now $1 + pdns_control bind-reload-now $1 | grep "no such domain" # In case the update cannot be done, it might be because the zone wasn't loaded at all. - if [ $? -ne 0 ]; then + if [ $? -eq 0 ]; then pdns_control bind-add-zone $1 $DIR/$1 fi }