source: trunk/third/moira/gen/hesiod.sh @ 24319

Revision 24319, 2.8 KB checked in by broder, 14 years ago (diff)
New Moira snapshot from SVN.
Line 
1#!/bin/sh
2# This script performs updates of hesiod files on hesiod servers.
3# $HeadURL: svn+ssh://svn.mit.edu/moira/trunk/moira/gen/hesiod.sh $ $Id: hesiod.sh 3956 2010-01-05 20:56:56Z zacheiss $
4
5if [ -d /var/athena ] && [ -w /var/athena ]; then
6    exec >/var/athena/moira_update.log 2>&1
7else
8    exec >/tmp/moira_update.log 2>&1
9fi
10
11set -x
12
13PATH=/etc:/bin:/usr/bin:/usr/etc:/usr/athena/etc
14export PATH
15
16# The following exit codes are defined and MUST BE CONSISTENT with the
17# error codes the library uses:
18MR_HESFILE=47836472
19MR_MISSINGFILE=47836473
20MR_NAMED=47836475
21MR_TARERR=47836476
22
23umask 022
24
25# File that will contain the necessary information to be updated
26TARFILE=/var/tmp/hesiod.out
27# Directory into which we will empty the tarfile
28SRC_DIR=/etc/athena/_nameserver
29# Directory into which we will put the final product
30DEST_DIR=/etc/athena/nameserver
31
32INIT=/etc/init.d/athena-bind
33NAMED_PID=/var/athena/named.pid
34
35# Create the destination directory if it doesn't exist
36if test ! -d $DEST_DIR
37then
38   rm -f $DEST_DIR
39   mkdir $DEST_DIR
40   chmod 755 $DEST_DIR
41fi
42
43# If $SRC_DIR does not already exist, make sure that it gets created
44# on the same parition as $DEST_DIR.
45if test ! -d $SRC_DIR
46then
47        # Tell linux cd/pwd not to be so "helpful".
48        # This will generate an ignorable error on older platforms.
49        set -P
50
51        cd $DEST_DIR
52        mkdir ../_nameserver
53        cd ../_nameserver
54        if test $SRC_DIR != `pwd`
55        then
56                ln -s `pwd` $SRC_DIR
57        fi
58fi
59
60# make sure SRC_DIR is empty
61/bin/rm -rf $SRC_DIR/*
62
63# Alert if tarfile doesn't exist
64if test ! -r $TARFILE
65then
66        exit $MR_MISSINGFILE
67fi
68
69cd $SRC_DIR
70tar xvf $TARFILE
71# Don't put up with errors extracting the information
72if test $? -ne 0
73then
74   exit $MR_TARERR
75fi
76for file in *
77do
78   # Make sure the file is not zero-length
79   if test ! -z $file
80   then
81      chmod o+r $file
82      mv -f $file $DEST_DIR
83      if test $? -ne 0
84      then
85          exit $MR_HESFILE
86      fi
87   else
88      rm -f $file
89      exit $MR_MISSINGFILE
90   fi
91done
92
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
97# First, get statistics
98/usr/athena/etc/rndc stats
99sleep 1
100$INIT stop
101rm -f $NAMED_PID
102
103# Restart named.
104$INIT start
105sleep 1
106# This timeout is implemented by having the shell check TIMEOUT times
107# for the existance of $NAMED_PID and to sleep INTERVAL seconds
108# between each check.
109
110TIMEOUT=60                      # number of INTERVALS until timeout
111INTERVAL=60                     # number of seconds between checks
112i=0
113while test $i -lt $TIMEOUT
114do
115   if test -f $NAMED_PID
116   then
117        break
118   fi
119   sleep $INTERVAL
120   i=`expr $i + 1`
121done
122echo out of timeout loop
123# Did it time out?
124if test $i -eq $TIMEOUT
125then
126        exit $MR_NAMED
127fi
128echo no timeout
129# Clean up!
130rm -f $TARFILE
131echo removed tarfile
132rm -f $0
133echo removed self
134
135exit 0
Note: See TracBrowser for help on using the repository browser.