]>
Commit | Line | Data |
---|---|---|
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 | chdir $DEST_DIR | |
48 | mkdir ../_nameserver | |
49 | chdir ../_nameserver | |
50 | if test $SRC_DIR != `pwd` | |
51 | then | |
52 | ln -s `pwd` $SRC_DIR | |
53 | fi | |
54 | fi | |
55 | ||
56 | # make sure SRC_DIR is empty | |
57 | /bin/rm -rf $SRC_DIR/* | |
58 | ||
59 | # Alert if tarfile doesn't exist | |
60 | if test ! -r $TARFILE | |
61 | then | |
62 | exit $MR_MISSINGFILE | |
63 | fi | |
64 | ||
65 | cd $SRC_DIR | |
66 | tar xvf $TARFILE | |
67 | # Don't put up with errors extracting the information | |
68 | if test $? -ne 0 | |
69 | then | |
70 | exit $MR_TARERR | |
71 | fi | |
72 | for file in * | |
73 | do | |
74 | # Make sure the file is not zero-length | |
75 | if test ! -z $file | |
76 | then | |
77 | mv -f $file $DEST_DIR | |
78 | if test $? -ne 0 | |
79 | then | |
80 | exit $MR_HESFILE | |
81 | fi | |
82 | else | |
83 | rm -f $file | |
84 | exit $MR_MISSINGFILE | |
85 | fi | |
86 | done | |
87 | ||
88 | # Kill off the current named and remove the named.pid file. It is | |
89 | # important that this file be removed since the script uses its | |
90 | # existance as evidence that named as has been successfully restarted. | |
91 | ||
92 | # First, get statistics | |
93 | kill -ILL `cat $NAMED_PID` | |
94 | sleep 1 | |
95 | kill -KILL `cat $NAMED_PID` | |
96 | rm -f $NAMED_PID | |
97 | ||
98 | # Restart named. | |
99 | $NAMED | |
100 | echo named started | |
101 | ||
102 | sleep 1 | |
103 | # This timeout is implemented by having the shell check TIMEOUT times | |
104 | # for the existance of $NAMED_PID and to sleep INTERVAL seconds | |
105 | # between each check. | |
106 | ||
107 | TIMEOUT=60 # number of INTERVALS until timeout | |
108 | INTERVAL=60 # number of seconds between checks | |
109 | i=0 | |
110 | while test $i -lt $TIMEOUT | |
111 | do | |
112 | if test -f $NAMED_PID | |
113 | then | |
114 | break | |
115 | fi | |
116 | sleep $INTERVAL | |
117 | i=`expr $i + 1` | |
118 | done | |
119 | echo out of timeout loop | |
120 | # Did it time out? | |
121 | if test $i -eq $TIMEOUT | |
122 | then | |
123 | exit $MR_NAMED | |
124 | fi | |
125 | echo no timeout | |
126 | # Clean up! | |
127 | rm -f $TARFILE | |
128 | echo removed tarfile | |
129 | rm -f $0 | |
130 | echo removed self | |
131 | ||
132 | exit 0 |