]> andersk Git - moira.git/blame - gen/hesiod.sh
what's currently running on sms
[moira.git] / gen / hesiod.sh
CommitLineData
abe0e1b9 1#!/bin/csh -f -x
39f6c9df 2# This script performs updates of hesiod files on hesiod servers.
abe0e1b9 3# $Source$
4echo '$Header$'
39f6c9df 5
6# The following exit codes are defined and MUST BE CONSISTENT with the
7# SMS error codes the library uses:
8set SMS_HESFILE = 47836472
9set SMS_MISSINGFILE = 47836473
10set SMS_NAMED = 47836475
11set SMS_TARERR = 47836476
12
abe0e1b9 13umask 22
14
39f6c9df 15# File that will contain the necessary information to be updated
16set TARFILE=/tmp/hesiod.out
17# Directory into which we will empty the tarfile
18set SRC_DIR=/etc/athena/_nameserver
19# Directory into which we will put the final product
20set DEST_DIR=/etc/athena/nameserver
abe0e1b9 21# Files to verify nameserver loaded
22set CHECKFILES="passwd.db pobox.db cluster.db grplist.db group.db"
39f6c9df 23
24# Create the destination directory if it doesn't exist
25if (! -d $DEST_DIR) then
26 /bin/rm -f $DEST_DIR
27 /bin/mkdir $DEST_DIR
28 /bin/chmod 755 $DEST_DIR
29endif
30
abe0e1b9 31# If $SRC_DIR does not already exist, make sure that it gets created
32# on the same parition as $DEST_DIR.
33if (! -d $SRC_DIR) then
34 chdir $DEST_DIR
35 mkdir ../_nameserver
36 chdir ../_nameserver
37 if ($SRC_DIR != `pwd`) ln -s `pwd` $SRC_DIR
39f6c9df 38endif
39f6c9df 39
40# Alert if tarfile doesn't exist
de9119eb 41if (! -r $TARFILE) exit $SMS_MISSINGFILE
39f6c9df 42
43# Empty the tar file one file at a time and move each file to the
44# appropriate place only if it is not zero length.
de56407f 45cd $SRC_DIR
de9119eb 46foreach file (`/bin/tar tf $TARFILE | awk '{print $1}' | sed 's;/$;;'`)
47 if (. == $file) continue
39f6c9df 48
49 rm -rf $file
50 echo extracting $file
51 /bin/tar xf $TARFILE $file
52 # Don't put up with errors extracting the information
de9119eb 53 if ($status) exit $SMS_TARERR
39f6c9df 54 # Make sure the file is not zero-length
55 if (! -z $file) then
56 /bin/mv -f $file $DEST_DIR
de9119eb 57 if ($status != 0) exit $SMS_HESFILE
39f6c9df 58 else
59 /bin/rm -f $file
de9119eb 60 exit $SMS_MISSINGFILE
39f6c9df 61 endif
62end
de56407f 63
39f6c9df 64# Kill off the current named and remove the named.pid file. It is
65# important that this file be removed since the script uses its
66# existance as evidence that named as has been successfully restarted.
67
68# Use /bin/kill because, due to a bug in some versions of csh, failure
69# of a builtin will cause the script to abort
70/bin/kill -KILL `/bin/cat /etc/named.pid`
71rm -f /etc/named.pid
72
73# Restart named.
74(unlimit; /etc/named)
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
80set TIMEOUT=60 # number of INTERVALS until timeout
81set INTERVAL=60 # number of seconds between checks
82set i = 0
83while ($i < $TIMEOUT)
84 sleep $INTERVAL
85 if (-f /etc/named.pid) break
86 @ i++
87end
88
89# Did it time out?
de9119eb 90if ($i == $TIMEOUT) exit $SMS_NAMED
39f6c9df 91
abe0e1b9 92# Verify that the nameserver is answering queries for the new data
93cd $DEST_DIR
94foreach f ( $CHECKFILES )
95 set temp=`tac $f | egrep -v '^;' | head -1`
96 set hes=`/bin/echo $temp | awk '{print $1}'`
97 set ent=`echo $hes | rev | sed 's/\(.*\)\.\(.*\)/\2/' | rev`
98 set type=`echo $hes | rev | sed 's/\(.*\)\.\(.*\)/\1/' | rev`
99 hesinfo $ent $type > /dev/null
100 if ($status == 1) then
101 exit $SMS_HESFILE
102 endif
103end
104
39f6c9df 105# Clean up!
106/bin/rm -f $TARFILE
107/bin/rm -f $0
f89684dc 108
39f6c9df 109exit 0
This page took 1.883997 seconds and 5 git commands to generate.