ldirectord_vips

Charles Bennington <[email protected]>
Newsgroups gmane.linux.highavailability.ultramonkey
Message-ID <[email protected]>
I use ldirectord for an HA pair of linux load balancers, and I was
having trouble managing the VIPs during failover as I had to update the
haresources file every time I added or removed a VIP. I don't know if
anyone else has run in to this problem, but if you have, the following
resource script might be useful.

It aggregates the return codes from multiple IPaddr2 calls and uses them
to produce a single return code to heartbeat.

I launch it from haresources as follows.  Works well for me.

Charles

----------------- /etc/ha.d/haresources 8< ----------------------------

lbhost.domain.com \
        <outside admin VIP> \
        IPaddr2::<internal gateway IP>/<internal netmask bits>/<internal
interface> \
        ldirectord_vips::ldirectord.cf::<external interface>/<external
netmask bits> \
        ldirectord::ldirectord.cf \
        LVSSyncDaemonSwap::master::<external interface>

------------------------- 8< ------------------------------------------

(
	where <outside admin VIP> is something like 10.0.0.2
	<internal gateway IP> is something like 10.1.0.1
	<internal netmask bits> might be 24
	<internal interface> might be eth1 or bond1
	<external interface> might be eth0 or bond0
	<external netmask bits> might be 24

	and all of the external VIPs are read from ldirectord.cf
)


----------------/etc/ha.d/resource.d 8< ------------------------------
#!/bin/sh

# A resource script to run IPaddr2 for each virtual address in the supplied
# config file and attach it to the specified interface.

# The return code is the average of all return codes.  This may not be
desirable
# if it starts trying to return fractions, so this variable is cast as
integer

HA_ROOT=/etc/ha.d
# Source function library.
. ${HA_ROOT}/shellfuncs

usage() {
        cat <<EOF
usage:
$0 config_file external_device[/mask] (start|stop|status|monitor)
EOF
        }


CONFIG=$1
DEVICE=$2
ACTION=$3
MASK="16"

INDEX=0
RC[$INDEX]=0
declare -i RC_RETURN

if echo ${DEVICE} | grep -q -s '/'
then
        MASK=`echo ${DEVICE} | cut -d'/' -f2`
        DEVICE=`echo ${DEVICE} | cut -d'/' -f1`
fi

do_action() {
        RC_SUM=0
        RC_COUNT=0
        for IP in `grep virtual= ${HA_ROOT}/${CONFIG}|cut -d'=' -f2|cut
-d':' -f1|sort -n`
        do
                ha_log "IPaddr2::${IP}/${MASK}/${DEVICE} $1"
                ${HA_ROOT}/resource.d/IPaddr2 ${IP}/${MASK}/${DEVICE} $1
                RC=$?
                RC_SUM=$((RC_SUM + RC))
                RC_COUNT=$((++RC_COUNT))
        done
        RC_RETURN=$((RC_SUM/RC_COUNT))
        return $RC_RETURN
        }

case ${ACTION} in
        start|stop|status|monitor)
                do_action ${ACTION} 2>&1 > /dev/null
                RC=$?
                case ${ACTION} in
                status)
                        if [ ${RC} -eq 0 ]
                        then
                                echo "running"
                        else
                                echo "stopped"
                        fi
                        ;;
                monitor)
                        if [ ${RC} -eq 0 ]
                        then
                                echo "OK"
                        else
                                echo "down"
                        fi
                        ;;
                esac
                ;;
        *)
                usage
                RC=1
                ;;
        esac

exit ${RC}
------------------------------ 8< ----------------------------------


-- 
Ultra Monkey - http://www.ultramonkey.org/
To UNSUBSCRIBE, email to [email protected], with a body:
unsubscribe ultramonkey-users [email protected]
where "[email protected]" is YOUR email address.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.