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