]>
Commit | Line | Data |
---|---|---|
f8f5fe16 | 1 | #!/bin/csh -f |
39f6c9df | 2 | # This script performs updates of hesiod files on hesiod servers. |
f8f5fe16 | 3 | # $Header$ |
4 | ||
5 | set path=(/etc /bin /usr/bin /usr/etc /usr/athena/etc) | |
39f6c9df | 6 | |
7 | # The following exit codes are defined and MUST BE CONSISTENT with the | |
2ce085d2 | 8 | # MR error codes the library uses: |
9 | set MR_HESFILE = 47836472 | |
10 | set MR_MISSINGFILE = 47836473 | |
11 | set MR_NAMED = 47836475 | |
12 | set MR_TARERR = 47836476 | |
39f6c9df | 13 | |
abe0e1b9 | 14 | umask 22 |
15 | ||
39f6c9df | 16 | # File that will contain the necessary information to be updated |
d7e5ee08 | 17 | set TARFILE=/var/tmp/hesiod.out |
39f6c9df | 18 | # Directory into which we will empty the tarfile |
19 | set SRC_DIR=/etc/athena/_nameserver | |
20 | # Directory into which we will put the final product | |
21 | set DEST_DIR=/etc/athena/nameserver | |
22 | ||
23 | # Create the destination directory if it doesn't exist | |
24 | if (! -d $DEST_DIR) then | |
f8f5fe16 | 25 | rm -f $DEST_DIR |
26 | mkdir $DEST_DIR | |
27 | chmod 755 $DEST_DIR | |
39f6c9df | 28 | endif |
29 | ||
abe0e1b9 | 30 | # If $SRC_DIR does not already exist, make sure that it gets created |
31 | # on the same parition as $DEST_DIR. | |
32 | if (! -d $SRC_DIR) then | |
33 | chdir $DEST_DIR | |
34 | mkdir ../_nameserver | |
35 | chdir ../_nameserver | |
f8f5fe16 | 36 | if ($SRC_DIR != `pwd`) then |
37 | ln -s `pwd` $SRC_DIR | |
38 | endif | |
39f6c9df | 39 | endif |
39f6c9df | 40 | |
41 | # Alert if tarfile doesn't exist | |
2ce085d2 | 42 | if (! -r $TARFILE) exit $MR_MISSINGFILE |
39f6c9df | 43 | |
44 | # Empty the tar file one file at a time and move each file to the | |
45 | # appropriate place only if it is not zero length. | |
de56407f | 46 | cd $SRC_DIR |
f8f5fe16 | 47 | foreach file (`tar tf $TARFILE | awk '{print $1}' | sed 's;/$;;'`) |
de9119eb | 48 | if (. == $file) continue |
39f6c9df | 49 | |
50 | rm -rf $file | |
51 | echo extracting $file | |
f8f5fe16 | 52 | tar xf $TARFILE $file |
39f6c9df | 53 | # Don't put up with errors extracting the information |
2ce085d2 | 54 | if ($status) exit $MR_TARERR |
39f6c9df | 55 | # Make sure the file is not zero-length |
56 | if (! -z $file) then | |
f8f5fe16 | 57 | mv -f $file $DEST_DIR |
2ce085d2 | 58 | if ($status != 0) exit $MR_HESFILE |
39f6c9df | 59 | else |
f8f5fe16 | 60 | rm -f $file |
2ce085d2 | 61 | exit $MR_MISSINGFILE |
39f6c9df | 62 | endif |
63 | end | |
de56407f | 64 | |
39f6c9df | 65 | # Kill off the current named and remove the named.pid file. It is |
66 | # important that this file be removed since the script uses its | |
67 | # existance as evidence that named as has been successfully restarted. | |
68 | ||
f8f5fe16 | 69 | # First, get statistics |
d7e5ee08 | 70 | rm -f /usr/tmp/named.stats |
71 | ln -s /var/named.stats /usr/tmp/named.stats | |
72 | kill -6 `cat /etc/named.pid` | |
f8f5fe16 | 73 | sleep 1 |
39f6c9df | 74 | # Use /bin/kill because, due to a bug in some versions of csh, failure |
75 | # of a builtin will cause the script to abort | |
f8f5fe16 | 76 | kill -KILL `cat /etc/named.pid` |
39f6c9df | 77 | rm -f /etc/named.pid |
78 | ||
79 | # Restart named. | |
d7e5ee08 | 80 | # mv /etc/named.pid /etc/named.pid.restart |
81 | #(unlimit; /etc/named&) | |
82 | /etc/named | |
83 | #sleep 5 | |
84 | echo named started | |
39f6c9df | 85 | |
39f6c9df | 86 | # This timeout is implemented by having the shell check TIMEOUT times |
87 | # for the existance of /etc/named.pid and to sleep INTERVAL seconds | |
88 | # between each check. | |
89 | ||
90 | set TIMEOUT=60 # number of INTERVALS until timeout | |
91 | set INTERVAL=60 # number of seconds between checks | |
92 | set i = 0 | |
93 | while ($i < $TIMEOUT) | |
94 | sleep $INTERVAL | |
95 | if (-f /etc/named.pid) break | |
96 | @ i++ | |
97 | end | |
d7e5ee08 | 98 | echo out of timeout loop |
39f6c9df | 99 | # Did it time out? |
2ce085d2 | 100 | if ($i == $TIMEOUT) exit $MR_NAMED |
d7e5ee08 | 101 | echo no timeout |
39f6c9df | 102 | # Clean up! |
f8f5fe16 | 103 | rm -f $TARFILE |
d7e5ee08 | 104 | echo removed tarfile |
f8f5fe16 | 105 | rm -f $0 |
d7e5ee08 | 106 | echo removed self |
f89684dc | 107 | |
39f6c9df | 108 | exit 0 |