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