]>
Commit | Line | Data |
---|---|---|
ce52ba53 | 1 | #!/bin/sh |
5eaef520 | 2 | # This script performs updates of hesiod files on hesiod servers. |
f8f5fe16 | 3 | # $Header$ |
4 | ||
f4f32185 | 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 | ||
ce52ba53 | 11 | set -x |
12 | ||
13 | PATH=/etc:/bin:/usr/bin:/usr/etc:/usr/athena/etc | |
14 | export PATH | |
39f6c9df | 15 | |
16 | # The following exit codes are defined and MUST BE CONSISTENT with the | |
59ec8dae | 17 | # error codes the library uses: |
ce52ba53 | 18 | MR_HESFILE=47836472 |
19 | MR_MISSINGFILE=47836473 | |
20 | MR_NAMED=47836475 | |
21 | MR_TARERR=47836476 | |
39f6c9df | 22 | |
ce52ba53 | 23 | umask 022 |
abe0e1b9 | 24 | |
39f6c9df | 25 | # File that will contain the necessary information to be updated |
80349f41 | 26 | TARFILE=/var/tmp/hesiod.out |
39f6c9df | 27 | # Directory into which we will empty the tarfile |
ce52ba53 | 28 | SRC_DIR=/etc/athena/_nameserver |
39f6c9df | 29 | # Directory into which we will put the final product |
ce52ba53 | 30 | DEST_DIR=/etc/athena/nameserver |
31 | ||
a608f84c | 32 | INIT=/etc/init.d/athena-bind |
ce52ba53 | 33 | NAMED_PID=/var/athena/named.pid |
39f6c9df | 34 | |
35 | # Create the destination directory if it doesn't exist | |
ce52ba53 | 36 | if test ! -d $DEST_DIR |
37 | then | |
f8f5fe16 | 38 | rm -f $DEST_DIR |
39 | mkdir $DEST_DIR | |
40 | chmod 755 $DEST_DIR | |
ce52ba53 | 41 | fi |
39f6c9df | 42 | |
abe0e1b9 | 43 | # If $SRC_DIR does not already exist, make sure that it gets created |
44 | # on the same parition as $DEST_DIR. | |
ce52ba53 | 45 | if test ! -d $SRC_DIR |
46 | then | |
52a20deb | 47 | # Tell linux cd/pwd not to be so "helpful". |
48 | # This will generate an ignorable error on older platforms. | |
49 | set -P | |
50 | ||
f2a412ca | 51 | cd $DEST_DIR |
abe0e1b9 | 52 | mkdir ../_nameserver |
f2a412ca | 53 | cd ../_nameserver |
ce52ba53 | 54 | if test $SRC_DIR != `pwd` |
55 | then | |
f8f5fe16 | 56 | ln -s `pwd` $SRC_DIR |
ce52ba53 | 57 | fi |
58 | fi | |
59 | ||
60 | # make sure SRC_DIR is empty | |
61 | /bin/rm -rf $SRC_DIR/* | |
39f6c9df | 62 | |
63 | # Alert if tarfile doesn't exist | |
ce52ba53 | 64 | if test ! -r $TARFILE |
65 | then | |
66 | exit $MR_MISSINGFILE | |
67 | fi | |
39f6c9df | 68 | |
de56407f | 69 | cd $SRC_DIR |
ce52ba53 | 70 | tar xvf $TARFILE |
71 | # Don't put up with errors extracting the information | |
72 | if test $? -ne 0 | |
73 | then | |
74 | exit $MR_TARERR | |
75 | fi | |
76 | for file in * | |
77 | do | |
39f6c9df | 78 | # Make sure the file is not zero-length |
ce52ba53 | 79 | if test ! -z $file |
80 | then | |
a608f84c | 81 | chmod o+r $file |
f8f5fe16 | 82 | mv -f $file $DEST_DIR |
ce52ba53 | 83 | if test $? -ne 0 |
84 | then | |
85 | exit $MR_HESFILE | |
86 | fi | |
39f6c9df | 87 | else |
f8f5fe16 | 88 | rm -f $file |
2ce085d2 | 89 | exit $MR_MISSINGFILE |
ce52ba53 | 90 | fi |
91 | done | |
de56407f | 92 | |
39f6c9df | 93 | # Kill off the current named and remove the named.pid file. It is |
94 | # important that this file be removed since the script uses its | |
95 | # existance as evidence that named as has been successfully restarted. | |
96 | ||
f8f5fe16 | 97 | # First, get statistics |
0041862d | 98 | /usr/athena/etc/rndc stats |
f8f5fe16 | 99 | sleep 1 |
a608f84c | 100 | $INIT stop |
ce52ba53 | 101 | rm -f $NAMED_PID |
39f6c9df | 102 | |
103 | # Restart named. | |
a608f84c | 104 | $INIT start |
ce52ba53 | 105 | sleep 1 |
39f6c9df | 106 | # This timeout is implemented by having the shell check TIMEOUT times |
ce52ba53 | 107 | # for the existance of $NAMED_PID and to sleep INTERVAL seconds |
39f6c9df | 108 | # between each check. |
109 | ||
ce52ba53 | 110 | TIMEOUT=60 # number of INTERVALS until timeout |
111 | INTERVAL=60 # number of seconds between checks | |
112 | i=0 | |
113 | while test $i -lt $TIMEOUT | |
114 | do | |
115 | if test -f $NAMED_PID | |
116 | then | |
117 | break | |
118 | fi | |
39f6c9df | 119 | sleep $INTERVAL |
ce52ba53 | 120 | i=`expr $i + 1` |
121 | done | |
d7e5ee08 | 122 | echo out of timeout loop |
39f6c9df | 123 | # Did it time out? |
ce52ba53 | 124 | if test $i -eq $TIMEOUT |
125 | then | |
126 | exit $MR_NAMED | |
127 | fi | |
d7e5ee08 | 128 | echo no timeout |
39f6c9df | 129 | # Clean up! |
f8f5fe16 | 130 | rm -f $TARFILE |
d7e5ee08 | 131 | echo removed tarfile |
f8f5fe16 | 132 | rm -f $0 |
d7e5ee08 | 133 | echo removed self |
f89684dc | 134 | |
39f6c9df | 135 | exit 0 |