Bob Hutchinson wrote:
On 23/09/04 00:17, Bill Shupp wrote:
Darrel O'Pry wrote:
I ran into a problem the other day on a testing server. Apache was stopped on the server hosting vegaDNS, and well I lost DNS to the whole test bed for a little bit :). Easy enough to fix in the situation, restart apache and all is well, but losing dns for a bit can blow if you have a good number of users. I made some changes to update-data.sh to avoid this, kind of dirty. I was wondering if anyone else had a better idea, or anything I overlooked to avoid this particular problem. This solution will keep the original DNS for any servers that are unavailable.
for VD in $VEGADNS ; do A=$[$A+1] if wget -q -O "$TINYDNSDIR/root/data.srv-$A.tmp" $VD?state=get_data; then mv $TINYDNSDIR/root/data.srv-$A.tmp $TINYDNSDIR/root/data.srv-$A fi cat "$TINYDNSDIR/root/data.srv-$A" >>$TINYDNSDIR/root/data done
.darrel.
Yeah, I agree there should be a check for the exit code of wget. I'll add this to the the next release.
But for the code above, shouldn't your "fi" be below the "cat" line?
Also, a test for filesize might not be amiss, I have had a zero size data appear when the mysql server was down :-(
if [ -s "$TINYDNSDIR/root/data.srv-$A.tmp" ]; then
# do it
fi
Ok, I have updated update-data.sh to cp the data file, rather than move it (in case later processing fails). All further processing is done on data.new, rather than data. It also checks the return status of wget, as well as the file size of the resulting data file for EACH VegaDNS server. If any fail or result on a 0 size file, update-data.sh generates and error and exits.
Anyone see any problems with the new attached script?
Regards,
Bill
#!/bin/bash
# The FULL path to the index.php file for the VegaDNS server VEGADNS='http://127.0.0.1/shupp/vegadns-0.9b1/index.php' # NOTE: You can get updates from multiple VegaDNS servers if # desired. Simply separate them by spaces like so: # VEGADNS='http://server1/vegadns-x.x/index.php http://server2/vegadns-x.x/index.php' # Path to the tinydns directory TINYDNSDIR=/etc/tinydns CUR="$TINYDNSDIR/root/data" OLD="$TINYDNSDIR/root/data.old" NEW="$TINYDNSDIR/root/data.new" cp $CUR $OLD if [ -f "$NEW" ] ; then rm $NEW fi A=$[0] for VD in $VEGADNS ; do A=$[$A+1] if wget -q -O "$TINYDNSDIR/root/data.srv-$A" $VD?state=get_data ; then if [ -s "$TINYDNSDIR/root/data.srv-$A" ] ; then cat "$TINYDNSDIR/root/data.srv-$A" >>$NEW else echo "ERROR: $TINYDNSDIR/root/data.srv-$A does not have a size greater than zero" exit fi else echo "ERROR: wget did not return 0 when accessing $VD?state=get_data" exit fi done # Don't run make if the files havn't changed OLDSUM=$(sum $OLD) NEWSUM=$(sum $NEW) if [ "$OLDSUM" != "$NEWSUM" ]; then mv $NEW $CUR (cd $TINYDNSDIR/root ; make -s) fi
