2024-11-23 15:06:33 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# Primary sends files in $DIR.
|
|
|
|
DIR="/var/powerdns/"
|
|
|
|
|
|
|
|
local_update() {
|
|
|
|
echo "update domain $1"
|
2024-11-23 15:53:04 +01:00
|
|
|
pdns_control bind-reload-now $1 | grep "no such domain"
|
2024-11-23 15:06:33 +01:00
|
|
|
|
|
|
|
# In case the update cannot be done, it might be because the zone wasn't loaded at all.
|
2024-11-23 15:53:04 +01:00
|
|
|
if [ $? -eq 0 ]; then
|
2024-11-23 15:06:33 +01:00
|
|
|
pdns_control bind-add-zone $1 $DIR/$1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
local_delete() { echo "TODO: delete domain $1" ; }
|
|
|
|
|
|
|
|
action() {
|
|
|
|
event=$1
|
|
|
|
file=$2
|
|
|
|
|
|
|
|
echo $event | grep "CLOSE_WRITE" >/dev/null
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "$file has been modified"
|
|
|
|
local_update $file
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo $event | grep "DELETE" >/dev/null
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "$file has been deleted"
|
|
|
|
local_delete $file
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# NOTE: primary nameserver sends files in $DIR upon modification or remove them
|
|
|
|
#
|
|
|
|
# Therefore, the different interesting actions we should monitor are:
|
|
|
|
# - close_write: a zone file has been modified
|
|
|
|
# - delete: a domain has been removed
|
|
|
|
opts="-e close_write -e delete -m"
|
|
|
|
echo "inotifywait ${opts} --format '%:e %f' $DIR"
|
|
|
|
inotifywait ${opts} --format '%:e %f' $DIR | while read FILE; do action $FILE ; done
|