]>
Commit | Line | Data |
---|---|---|
ce52ba53 | 1 | #!/bin/sh |
5eaef520 | 2 | # This script performs updates of hesiod files on hesiod servers. |
f8f5fe16 | 3 | # $Header$ |
4 | ||
ce52ba53 | 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 | |
39f6c9df | 10 | |
11 | # The following exit codes are defined and MUST BE CONSISTENT with the | |
59ec8dae | 12 | # error codes the library uses: |
ce52ba53 | 13 | MR_HESFILE=47836472 |
14 | MR_MISSINGFILE=47836473 | |
15 | MR_NAMED=47836475 | |
16 | MR_TARERR=47836476 | |
39f6c9df | 17 | |
ce52ba53 | 18 | umask 022 |
abe0e1b9 | 19 | |
39f6c9df | 20 | # File that will contain the necessary information to be updated |
ce52ba53 | 21 | TARFILE=/var/tmp/nhesiod.out |
39f6c9df | 22 | # Directory into which we will empty the tarfile |
ce52ba53 | 23 | SRC_DIR=/etc/athena/_nameserver |
39f6c9df | 24 | # Directory into which we will put the final product |
ce52ba53 | 25 | DEST_DIR=/etc/athena/nameserver |
26 | ||
27 | NAMED=/etc/athena/named | |
28 | NAMED_PID=/var/athena/named.pid | |
39f6c9df | 29 | |
30 | # Create the destination directory if it doesn't exist | |
ce52ba53 | 31 | if test ! -d $DEST_DIR |
32 | then | |
f8f5fe16 | 33 | rm -f $DEST_DIR |
34 | mkdir $DEST_DIR | |
35 | chmod 755 $DEST_DIR | |
ce52ba53 | 36 | fi |
39f6c9df | 37 | |
abe0e1b9 | 38 | # If $SRC_DIR does not already exist, make sure that it gets created |
39 | # on the same parition as $DEST_DIR. | |
ce52ba53 | 40 | if test ! -d $SRC_DIR |
41 | then | |
abe0e1b9 | 42 | chdir $DEST_DIR |
43 | mkdir ../_nameserver | |
44 | chdir ../_nameserver | |
ce52ba53 | 45 | if test $SRC_DIR != `pwd` |
46 | then | |
f8f5fe16 | 47 | ln -s `pwd` $SRC_DIR |
ce52ba53 | 48 | fi |
49 | fi | |
50 | ||
51 | # make sure SRC_DIR is empty | |
52 | /bin/rm -rf $SRC_DIR/* | |
39f6c9df | 53 | |
54 | # Alert if tarfile doesn't exist | |
ce52ba53 | 55 | if test ! -r $TARFILE |
56 | then | |
57 | exit $MR_MISSINGFILE | |
58 | fi | |
39f6c9df | 59 | |
de56407f | 60 | cd $SRC_DIR |
ce52ba53 | 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 | |
39f6c9df | 69 | # Make sure the file is not zero-length |
ce52ba53 | 70 | if test ! -z $file |
71 | then | |
f8f5fe16 | 72 | mv -f $file $DEST_DIR |
ce52ba53 | 73 | if test $? -ne 0 |
74 | then | |
75 | exit $MR_HESFILE | |
76 | fi | |
39f6c9df | 77 | else |
f8f5fe16 | 78 | rm -f $file |
2ce085d2 | 79 | exit $MR_MISSINGFILE |
ce52ba53 | 80 | fi |
81 | done | |
de56407f | 82 | |
39f6c9df | 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 | ||
f8f5fe16 | 87 | # First, get statistics |
ce52ba53 | 88 | kill -ILL `cat $NAMED_PID` |
f8f5fe16 | 89 | sleep 1 |
ce52ba53 | 90 | kill -KILL `cat $NAMED_PID` |
91 | rm -f $NAMED_PID | |
39f6c9df | 92 | |
93 | # Restart named. | |
ce52ba53 | 94 | $NAMED |
d7e5ee08 | 95 | echo named started |
39f6c9df | 96 | |
ce52ba53 | 97 | sleep 1 |
39f6c9df | 98 | # This timeout is implemented by having the shell check TIMEOUT times |
ce52ba53 | 99 | # for the existance of $NAMED_PID and to sleep INTERVAL seconds |
39f6c9df | 100 | # between each check. |
101 | ||
ce52ba53 | 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 | |
39f6c9df | 111 | sleep $INTERVAL |
ce52ba53 | 112 | i=`expr $i + 1` |
113 | done | |
d7e5ee08 | 114 | echo out of timeout loop |
39f6c9df | 115 | # Did it time out? |
ce52ba53 | 116 | if test $i -eq $TIMEOUT |
117 | then | |
118 | exit $MR_NAMED | |
119 | fi | |
d7e5ee08 | 120 | echo no timeout |
39f6c9df | 121 | # Clean up! |
f8f5fe16 | 122 | rm -f $TARFILE |
d7e5ee08 | 123 | echo removed tarfile |
f8f5fe16 | 124 | rm -f $0 |
d7e5ee08 | 125 | echo removed self |
f89684dc | 126 | |
39f6c9df | 127 | exit 0 |