709b0f5
#!/bin/sh
709b0f5
12a40fb
# Paul Wouters <paul@xelerance.com>
12a40fb
# This folds back zone updates, dynamic updates, etc that nsd records
70a5a00
# in the ixfr.db and nsd.db files back into the zone files or vice-versa
709b0f5
a236fa7
# Default settings - do not edit these but /etc/sysconfig/nsd instead!
a236fa7
NSD_CONF="/etc/nsd/nsd.conf"
a236fa7
NSDC_PROG="/usr/sbin/nsdc"
a236fa7
NSD_CHECKCONF_PROG="/usr/sbin/nsd-checkconf"
a236fa7
NSD_AUTORELOAD="yes"
a236fa7
a236fa7
# Read in local settings.
a236fa7
[ -r /etc/sysconfig/nsd ] && . /etc/sysconfig/nsd
a236fa7
12a40fb
# Ideally check if ixfr.db newer then any zones, only then do
a236fa7
$NSDC_PROG -c $NSD_CONF patch > /dev/null 2>&1
da6cbb8
217da49
# We try to only rebuild/reload when neccessary. If 1 zone is newer,
217da49
# we need to rebuild the db file.
217da49
# This might give problems with huge zones, eg TLD's, which cannot
217da49
# complete this operation within an hour, but it should work fine for
217da49
# most other uses.
da6cbb8
a236fa7
case "$NSD_AUTORELOAD" in
a236fa7
	[Yy]|[Yy][Ee][Ss])
a236fa7
		database="`$NSD_CHECKCONF_PROG -o database $NSD_CONF`"
a236fa7
		$NSD_CHECKCONF_PROG -v $NSD_CONF | grep zonefile: | sed "s/^.*\"\(.*\)\"/\1/" | while read zonefile
a236fa7
		do
a236fa7
			if [ $zonefile -nt $database ]
a236fa7
			then
a236fa7
				echo "Zone $zonefile update requires database rebuild"
a236fa7
				$NSDC_PROG rebuild > /dev/null 2>&1
a236fa7
				$NSDC_PROG reload > /dev/null 2>&1
a236fa7
				break
a236fa7
			fi
a236fa7
		done
a236fa7
		;;
a236fa7
	*)
a236fa7
		;;	
a236fa7
esac
709b0f5
709b0f5
# nsd checks the serial in notify requests, so its better to send an
12a40fb
# occasional redundant notify, then to miss it.
12a40fb
# According to the nsd team, this is no longer neccessary
a236fa7
# $NSDC_PROG notify > /dev/null 2>&1