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