source: hybrid/branches/releng-10/nanobsd/files/usr/local/sbin/fetchzone.sh@ 12525

Last change on this file since 12525 was 10136, checked in by richardvm, 13 years ago

domme toevoeging van proxy files

  • Property svn:executable set to *
File size: 2.0 KB
Line 
1#!/bin/sh
2# $Id: fetchzone.sh 9970 2012-02-15 18:04:47Z rick $
3#
4# Wireless Leiden specific configuration to fetch DNS zones
5# used by MaraDNS
6#
7
8# Script is running in deamon mode to discriptors available, so make sure to
9# close them to avoid 'hanging' scripts.
10exec <&-
11exec 1>/dev/null
12exec 2>/dev/null
13
14
15# Updates of $ZONES we are going to fetch from the $SERVER every $IDLE seconds
16ZONES="wleiden.net. 16.172.in-addr.arpa. 17.172.in-addr.arpa.
1718.172.in-addr.arpa. 19.172.in-addr.arpa. 20.172.in-addr.arpa.
1821.172.in-addr.arpa. 22.172.in-addr.arpa. 23.172.in-addr.arpa.
1924.172.in-addr.arpa. 25.172.in-addr.arpa. 26.172.in-addr.arpa.
2027.172.in-addr.arpa. 28.172.in-addr.arpa. 29.172.in-addr.arpa.
2130.172.in-addr.arpa. 31.172.in-addr.arpa."
22SERVER=172.16.4.46
23IDLE=3600
24
25LOGFILE=/var/log/fetchzone.log
26PIDFILE=/var/run/fetchzone.pid
27### END OF USER CONFIGURABLE VARIABLES ###
28
29TAGNAME=`basename $0 .sh`
30# Create logging service
31log() {
32 echo `date "+%b %e %T"`":" $* >> ${LOGFILE}
33 echo $* | logger -t "$TAGNAME"
34}
35
36# Register PID
37PID=$$
38echo ${PID} > ${PIDFILE}
39log "[INFO] Fetchzone starting with PID: $PID"
40
41# Make me a deamon script
42while [ true ]; do
43
44 CHANGED_ZONES=""
45 # Run through multiple zones
46 for ZONE in ${ZONES}; do
47 # (re) Set some extra vars
48 TMPFILE=/tmp/dns-tmp-${ZONE}
49 REALFILE=/usr/local/etc/maradns/db.${ZONE}
50 # Execute Fetchzone
51 /usr/local/bin/fetchzone ${ZONE} ${SERVER} > ${TMPFILE}
52
53 # Did Fetchzone exit unhappy
54 if [ $? -ne 0 ]; then
55 # Something went wrong lets log it
56 log "[ERROR] [$ZONE] Errors found in fetchzone query"
57 continue
58 fi
59
60 # Are there any changes, we need to put active?
61 cmp -s ${TMPFILE} ${REALFILE}
62 if [ $? -ne 0 ]; then
63 log "[INFO] [$ZONE] Changes found"
64 cp ${TMPFILE} ${REALFILE}
65 CHANGED_ZONES="$CHANGED_ZONES $ZONE"
66 fi
67 done
68
69 # Maradns requires a restart to load new zonefile
70 if [ -n "$CHANGED_ZONES" ]; then
71 log "[INFO] `/usr/local/etc/rc.d/maradns restart`"
72 fi
73
74 # Next run in $IDLE seconds
75 sleep ${IDLE}
76done
77
Note: See TracBrowser for help on using the repository browser.