File: /volume1/@appstore/DNSServer/script/flushcache.sh
#!/bin/sh
ChrootDir="/var/packages/DNSServer/target/named"
RndcKeyFile=${ChrootDir}"/rndc.key"
BinDir="/var/packages/DNSServer/target/bin"
name="$1"
view="$2"
. /var/packages/DNSServer/scripts/start-stop-status
ChangeOwner
cd ${BinDir}
if [ "x" = "x$name" ]; then
./rndc -k ${RndcKeyFile} flush ${view}
else
./rndc -k ${RndcKeyFile} flushtree ${name} ${view}
# work around for this bug:
# -------------------------------------------------------------------------
# If create forward zone with a forwarder ip which
# doesn't contains the specified zone. After this zone create,
# any change of forwarder ip will flush doamin cache failed even
# this forwarder ip contains the specified zone.
# (ie. flush by ./rndc flushtree always fail)
#
# When this issue occurs,
# only ./rndc flush (ie. flush all domains) can solve the issue.
#--------------------------------------------------------------------------
result=`./dig @localhost "$name" +short`
if [ "$?" = "0" ] && [ "x$result" = "x" ]; then # use dig to find if flushtree fail or success
./rndc -k ${RndcKeyFile} flush ${view}
fi
fi