]> git.sthu.org Git - shutils.git/commitdiff
nsd-dynipwatch: --watchfile, let inotifywatch die
authorStefan Huber <shuber2@gmx.at>
Mon, 29 Oct 2012 11:16:11 +0000 (12:16 +0100)
committerStefan Huber <shuber2@gmx.at>
Mon, 29 Oct 2012 11:16:11 +0000 (12:16 +0100)
init.d/nsd-dynipwatch
nsd-dynipwatch

index 96963591fc080cedcc0e6d0ff00c3613c0a8ff8c..d7563da6ed0ae3b4541f28cbff5bbc082ba2b356 100755 (executable)
@@ -16,8 +16,7 @@
 . /lib/lsb/init-functions
 
 PIDFILE=/var/run/nsd-dynipwatch.pid
 . /lib/lsb/init-functions
 
 PIDFILE=/var/run/nsd-dynipwatch.pid
-IPFILE=/tmp/euklid.ip
-ARGS="/etc/nsd3/sthu.org.zone euklid ${IPFILE}"
+ARGS="/etc/nsd3/sthu.org.zone euklid"
 
 case "$1" in
 start)
 
 case "$1" in
 start)
index a002f9576b3f8fa49408fe58af40025801617faf..bfdb8407bad273f34f3cf78b7d3e5038be28a69d 100755 (executable)
@@ -1,12 +1,14 @@
 #!/bin/bash
 
 logfile=
 #!/bin/bash
 
 logfile=
+watchfile=
 
 while true; do
        case $1 in
                --log) logfile=$2; shift ;;
 
 while true; do
        case $1 in
                --log) logfile=$2; shift ;;
+               --watchfile) watchfile=$2; shift ;;
                -h|--help)
                -h|--help)
-                       echo "$0 [-f] [--log logfile] zonefile host watchfile"
+                       echo "$0 [--log logfile] [--watchfile /tmp/\${host}.ip] zonefile host"
                        exit 0
                        ;;
                *) break ;;
                        exit 0
                        ;;
                *) break ;;
@@ -17,11 +19,11 @@ done
 
 zonefile=$1
 host=$2
 
 zonefile=$1
 host=$2
-watchfile=$3
+[ -z "${watchfile}" ] && watchfile=/tmp/${host}.ip
 [ -z "${logfile}" ] && logfile="/var/log/nsd-dynipwatch-${host}.log"
 
 [ -z "${logfile}" ] && logfile="/var/log/nsd-dynipwatch-${host}.log"
 
-echo "logfile: ${logfile}"
 
 
+echo "Watch ${watchfile} for host ${host} and update ${zonefile}. Logfile: ${logfile}"
 
 
 function getAddrFromZonefile # <host> <zonefile>
 
 
 function getAddrFromZonefile # <host> <zonefile>
@@ -47,7 +49,10 @@ function setSerialInZonefile # <zonefile> <serial>
 function run()
 {
        while true; do
 function run()
 {
        while true; do
-               inotifywait -q -e close_write "${watchfile}"  > /dev/null
+               inotifywait -q -t 30 -e close_write "${watchfile}"  > /dev/null
+               ret=$?
+               [ "$ret" = "0" ] || continue
+
                oldip=`getAddrFromZonefile "${host}" "${zonefile}"`
                newip=`cat ${watchfile}`
                echo "`date '+%a %F %T'` :: ${oldip} => ${newip}."
                oldip=`getAddrFromZonefile "${host}" "${zonefile}"`
                newip=`cat ${watchfile}`
                echo "`date '+%a %F %T'` :: ${oldip} => ${newip}."
@@ -68,5 +73,6 @@ function run()
        done
 }
 
        done
 }
 
+
 run >> $logfile
 
 run >> $logfile