diff options
| author | Paul Buetow <paul@buetow.org> | 2024-03-19 22:28:12 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-03-19 22:28:12 +0200 |
| commit | e14a5b471ab59b08d07f195778011ea68cb0e7d8 (patch) | |
| tree | a614a5cb9ba5b1a70a72923549a6aa7f9cf8e046 /frontends/scripts | |
| parent | f1137207e506d037aa4b9c85926554daafae5da2 (diff) | |
more on the DNS failover script
Diffstat (limited to 'frontends/scripts')
| -rw-r--r-- | frontends/scripts/dnsfailover.sh.tpl | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/frontends/scripts/dnsfailover.sh.tpl b/frontends/scripts/dnsfailover.sh.tpl index a92201b..050d42b 100644 --- a/frontends/scripts/dnsfailover.sh.tpl +++ b/frontends/scripts/dnsfailover.sh.tpl @@ -6,7 +6,7 @@ MASTER_AAAA=master_aaaa STANDBY_A=standby_a STANDBY_AAAA=standby_aaaa -transform_zone () { +transform () { sed -E ' /IN A .*; Enable failover/ { /^mirror/! { @@ -25,17 +25,40 @@ transform_zone () { } } / ; serial/ { - s/^( +) ([0-9]+) .*; (.*)/\1 '`date +%s`' ; \3/; + s/^( +) ([0-9]+) .*; (.*)/\1 '"`date +%s`"' ; \3/; } ' } failover_zone () { zone=$1 - cat $zone | transform_zone > $zone.new && \ - mv $zone $zone.bak && \ - mv $zone.new $zone - nsd-checkconf checkzone $zone + cat $zone | transform > $zone.new.tmp + + grep -v ' ; serial' $zone.new > $zone.new.noserial.tmp + grep -v ' ; serial' $zone > $zone.old.noserial.tmp + + diff $zone.new.noserial.tmp $zone.old.noserial.tmp + if [ $? -eq 0 ]; then + echo "zone $zone hasn't changed" + rm $zone.*.tmp + return + fi + + cp $zone $zone.bak + mv $zone.new.tmp $zone + rm $zone.*.tmp + nsd-control reload $zone + + dig $zone @localhost + # Todo: Use different return check, als ec may be 0 anyway + if [ $? -eq 0 ]; then + return + fi + + echo "Rolling back $zone changes" + cp $zone $zone.invalid + mv $zone.bak $zone + nsd-control reload $zone } for zone in $ZONES_DIR/snonux.foo.zone; do |
