From - Tue Dec  7 23:26:46 1999
X-POP3-Rcpt: wensong@dns1
Return-Path: <lvs-users-return-194-wensong=iinchina.net@LinuxVirtualServer.org>
Received: from smtp-exploder.teuto.net (backup.bi.teuto.net [212.8.197.26])
	by iinchina.net (8.9.3/8.9.3) with SMTP id GAA14877
	for <wensong@iinchina.net>; Wed, 10 Nov 1999 06:46:25 +0800
Received: (qmail 24282 invoked by uid 503); 9 Nov 1999 22:42:39 -0000
Mailing-List: contact lvs-users-help@LinuxVirtualServer.org; run by ezmlm
Precedence: bulk
list-help: <mailto:lvs-users-help@LinuxVirtualServer.org>
list-unsubscribe: <mailto:lvs-users-unsubscribe@LinuxVirtualServer.org>
list-post: <mailto:lvs-users@LinuxVirtualServer.org>
Delivered-To: mailing list lvs-users@LinuxVirtualServer.org
Received: (qmail 24275 invoked from network); 9 Nov 1999 22:42:38 -0000
Message-ID: <3828A355.E375BE63@wsc.com>
Date: Tue, 09 Nov 1999 17:42:29 -0500
From: Nick Christopher <nwc@wsc.com>
Organization: Wall Street Concepts
X-Mailer: Mozilla 4.6 [en] (WinNT; I)
X-Accept-Language: en
MIME-Version: 1.0
To: lvs-users@LinuxVirtualServer.org
Subject: A script that might be of use...
Content-Type: multipart/mixed;
 boundary="------------197DD860FCB85C763C94021D"
X-Mozilla-Status: 8001
X-Mozilla-Status2: 00000000
X-UIDL: <3828A355.E375BE63@wsc.com>

--------------197DD860FCB85C763C94021D
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit


I didn't want to deal with Satan, it's not that I'm religious, but I am
slothful :-)  Anyway, the mon approach to high availability was more
than I wanted to deal with. All I wanted was to pool several web servers
together.

The results, a pretty clean bash script that I run on my Director to
both start up the director and then monitor the real servers. It's about
2 pages of bash and uses GNU wget to "ping" the real servers.

Configure it by changing the values of the variables in the variable
definition block at the top.

The web servers all run linux here and are on a single class C with
firewall so tunneling seemed best.  Enjoy.

No warrantees implied or stated, no claims of usefulness in your galaxy.

--
Asking permission is too often simply seeking denial.


--------------197DD860FCB85C763C94021D
Content-Type: application/x-sh;
 name="httpdMonitor.sh"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="httpdMonitor.sh"

#!/bin/sh
# This script starts up a tunneling virtual server for httpd
# and then monitors all the known real servers removing
# and returning them as needed.
# 
# Only outside resource required is GNU wget.

cd `dirname $0`
SRCDIR=`pwd`

#
# Define variables
#

# Virtual Server variables
DIRECTOR=198.4.126.55
TCP_PORT=80
SERVERS="198.4.126.52 198.4.126.53"
LB=wlc

# General variables
SLEEPTIME=15
TMP=/tmp/mon.$$
DOWNHOSTS=$TMP/down
RETURN=0


function httpdPing()
{
    _HTTPDPING_IP=$1

    cd $TMP
    rm -rf index.html
    wget -q -T 5 -t 1 -nh http://$_HTTPDPING_IP
    if [ -f index.html ]; then
	true
    else
	false
    fi
}

function httpdState()
{
    _HS_IP=$1

    if [ -f $DOWNHOSTS/$_HS_IP ]; then
	false
    else
	true
    fi
}

function httpdChangeState()
{
    _HCS_IP=$1
    _HCS_STATE=$2

    if [ $2 = "up" ]; then
	/sbin/ipvsadm -a -t $DIRECTOR:$TCP_PORT -R $_HCS_IP -i
	rm -f $DOWNHOSTS/$_HCS_IP
	echo "$_HCS_IP now up."
    else
	/sbin/ipvsadm -d -t $DIRECTOR:$TCP_PORT -R $_HCS_IP
	date > $DOWNHOSTS/$_HCS_IP
	echo "$_HCS_IP now down."
    fi
}

mkdir -p $DOWNHOSTS

# Start up the DIRECTOR
/sbin/ifconfig eth0:0 $DIRECTOR netmask 255.255.255.255 broadcast $DIRECTOR up
/sbin/route add -host $DIRECTOR dev eth0:0
/sbin/ipvsadm -A -t $DIRECTOR:$TCP_PORT -s $LB

# Start by assuming all servers are up
for i in $SERVERS
do
    httpdChangeState $i up
done

# Now for the rest of time loop through the servers testing them
until [ 1 -ne 1 ]; do
    for i in $SERVERS
    do
	if ( httpdPing $i ) then
	    # httpd is up
	    if ( httpdState $i ) then
		true
	    else
		# httpd was down - back up!
		httpdChangeState $i up
	    fi
	else
	    # httpd is down
	    if ( httpdState $i ) then
		# httpd was up - has crashed!
		httpdChangeState $i down
	    else
		true
	    fi
        fi
    done
    sleep $SLEEPTIME
done


--------------197DD860FCB85C763C94021D
Content-Type: text/plain; charset=us-ascii

----------------------------------------------------------------------
LinuxVirtualServer.org mailing list - lvs-users@LinuxVirtualServer.org
To unsubscribe, e-mail: lvs-users-unsubscribe@LinuxVirtualServer.org
For additional commands, e-mail: lvs-users-help@LinuxVirtualServer.org
--------------197DD860FCB85C763C94021D--

