]> andersk Git - moira.git/blob - gen/hesiod.sh
fe5e84ce17d6510c83cce4a8ba01425f949179f8
[moira.git] / gen / hesiod.sh
1 #!/bin/sh
2 # This script performs updates of hesiod files on hesiod servers.
3 # $Header$
4
5 if [ -d /var/athena ] && [ -w /var/athena ]; then
6     exec >/var/athena/moira_update.log 2>&1
7 else
8     exec >/tmp/moira_update.log 2>&1 
9 fi
10
11 set -x 
12
13 PATH=/etc:/bin:/usr/bin:/usr/etc:/usr/athena/etc
14 export PATH
15
16 # The following exit codes are defined and MUST BE CONSISTENT with the
17 # error codes the library uses:
18 MR_HESFILE=47836472
19 MR_MISSINGFILE=47836473
20 MR_NAMED=47836475
21 MR_TARERR=47836476
22
23 umask 022
24
25 # File that will contain the necessary information to be updated
26 TARFILE=/var/tmp/hesiod.out
27 # Directory into which we will empty the tarfile
28 SRC_DIR=/etc/athena/_nameserver
29 # Directory into which we will put the final product
30 DEST_DIR=/etc/athena/nameserver
31
32 NAMED=/etc/athena/named
33 NAMED_PID=/var/athena/named.pid
34
35 # Create the destination directory if it doesn't exist
36 if test ! -d $DEST_DIR
37 then
38    rm -f $DEST_DIR
39    mkdir $DEST_DIR
40    chmod 755 $DEST_DIR
41 fi
42
43 # If $SRC_DIR does not already exist, make sure that it gets created
44 # on the same parition as $DEST_DIR.
45 if test ! -d $SRC_DIR
46 then
47         # Tell linux cd/pwd not to be so "helpful".
48         # This will generate an ignorable error on older platforms.
49         set -P
50
51         cd $DEST_DIR
52         mkdir ../_nameserver
53         cd ../_nameserver
54         if test $SRC_DIR != `pwd`
55         then
56                 ln -s `pwd` $SRC_DIR
57         fi
58 fi
59
60 # make sure SRC_DIR is empty
61 /bin/rm -rf $SRC_DIR/*
62
63 # Alert if tarfile doesn't exist
64 if test ! -r $TARFILE 
65 then
66         exit $MR_MISSINGFILE
67 fi
68
69 cd $SRC_DIR
70 tar xvf $TARFILE
71 # Don't put up with errors extracting the information
72 if test $? -ne 0
73 then
74    exit $MR_TARERR
75 fi
76 for file in *
77 do
78    # Make sure the file is not zero-length
79    if test ! -z $file
80    then
81       mv -f $file $DEST_DIR
82       if test $? -ne 0
83       then
84           exit $MR_HESFILE
85       fi
86    else
87       rm -f $file
88       exit $MR_MISSINGFILE
89    fi
90 done
91
92 # Kill off the current named and remove the named.pid file.  It is
93 # important that this file be removed since the script uses its
94 # existance as evidence that named as has been successfully restarted.
95
96 # First, get statistics
97 /usr/athena/etc/rndc stats
98 sleep 1
99 kill -KILL `cat $NAMED_PID`
100 rm -f $NAMED_PID
101
102 # Restart named.
103 $NAMED
104 echo named started
105
106 sleep 1
107 # This timeout is implemented by having the shell check TIMEOUT times
108 # for the existance of $NAMED_PID and to sleep INTERVAL seconds
109 # between each check.
110
111 TIMEOUT=60                      # number of INTERVALS until timeout
112 INTERVAL=60                     # number of seconds between checks
113 i=0
114 while test $i -lt $TIMEOUT
115 do
116    if test -f $NAMED_PID
117    then
118         break
119    fi
120    sleep $INTERVAL
121    i=`expr $i + 1`
122 done
123 echo out of timeout loop
124 # Did it time out?
125 if test $i -eq $TIMEOUT 
126 then
127         exit $MR_NAMED
128 fi
129 echo no timeout
130 # Clean up!
131 rm -f $TARFILE
132 echo removed tarfile
133 rm -f $0
134 echo removed self
135
136 exit 0
This page took 0.147485 seconds and 3 git commands to generate.