Alternate Pathing for ethernet

2007-12-25 11:40:00

> It's probably stupid question, but I can't find any sources for automating

> the switching to alternate network interface, if primary (or active)

> interface goes down when using AP 2.3.

>

> I can easely switch the active interface even w/o loosing my ssh-session,

> but the whole point is have this process automated.

>

> I believe (at least, I really-really hope), there should be some

> scripts/configs that allow automated switching for network interfaces,

> that covers most kind of network interface failure.

Well, I got no responses on this question.

Here's the script you can use to acomplish the automatic switching to

alternate network interface should active went down.

---------------------CUT HERE------------------------------------------

#!/bin/sh

#

# Original name: apcheck

#

# Author: Konstantin Orekhov <korekhov@taos.com>

#

# Date: Wed Nov 8 10:26:06 PST 2000

#

# Purpose: "Failover" for Alternate Pathing network metadevice.

#

# Assumptions: Machine has installed and correctly configured AP,

# at least 2 NICS, connected to the different

# switches (network is built with failover in mind).

# Also, see the end of script for better understanding.

#

# OS/platform: Written and tested on Solaris 8 on Sparc (E220R)

# Alternate Pathing 2.3, but should work on any other

# Sun machine with older Solaris and AP - the script

# is just using AP and system binaries.

#

# Feedbacks: Always welcome! My email above.

# Improvements: Always welcome! My email above.

# Success: Always glad to hear! My email above.

#

#############################################################################

# A little debugging

#set -x

# A variable variables :) (those that you really want to modify)

# List of people, who will be alerted in case of problems

# Actually, if there's a REAL problem with network -

# no emails can get an addressee, so ...

# Anyway, it's being used for reporting.

ALERT="root@machine"

# How many interfaces in metaether device?

# Crucial variable - make sure it has correct value.

NICS=2

# Targets - the nearest network devices (switches) for each device in metaether

# It's very important that they're named exactly after physical interfaces!

# (except that the vars should be in upper case - I like see vars in upper,

# case. If you don't or you want to run 1 external command less - make them

# in lower case AND remove translation from check() function.

# Once again - these IP addresses NOT the IP's of machine, they're IP's of

# respective switches, to which interfaces physically connected.

HME0=192.168.4.2

QFE0=192.168.4.3

# SBIN Binaries

SBIN_DIR=/usr/sbin

APCONFIG=$SBIN_DIR/apconfig

PING=$SBIN_DIR/ping

# BIN binaries

BIN_DIR=/usr/bin

RM=$BIN_DIR/rm

AWK=$BIN_DIR/awk

MAIL="$BIN_DIR/mailx -s"

CAT=$BIN_DIR/cat

CUT=$BIN_DIR/cut

TR=$BIN_DIR/tr

ID=$BIN_DIR/id

TAIL=$BIN_DIR/tail

GREP=$BIN_DIR/grep

DATE=$BIN_DIR/date

# Files and other

HOSTNAME=`$BIN_DIR/hostname`

LOCK=/tmp/apcheck.lock

LOG=/tmp/apcheck.log.$$

DETAILS=/tmp/apcheck.details.$$

METAINFO=/tmp/apcheck.metainfo.$$

###########################################################################

# Check if we called by UID 0 (apconfig needs root)

if [ `$ID | $CUT -c7-10` != "root" ]; then

        echo ""

        echo "$0: you must be root to run me!"

        echo "Exiting..."

        echo ""

        exit 1

fi

# Report function

report() {

        echo "Hostname: $HOSTNAME" > $LOG

        echo "Script name: $0" >> $LOG

        echo "Current date: `$DATE`" >> $LOG

        echo "Description: $1" >> $LOG

        echo "------------------------------------------------" >> $LOG

        if [ -f $DETAILS ]; then

                echo "" >> $LOG

                echo "Details:" >> $LOG

                $CAT $DETAILS >> $LOG

                $RM $DETAILS

                echo "------------------------------------------------" >> $LOG

                echo "" >> $LOG

        fi

        echo "End of report." >> $LOG

        echo "" >> $LOG

        $MAIL "$1" $ALERT < $LOG

        $RM $LOG

}

# Check/ping function

check() {

        # Terrible way to get the actual IP address from $1

        TARGET="echo \$`echo $1 | $TR [a-z] [A-Z]`"

        IP=`eval $TARGET`

        $PING $IP > $DETAILS 2>&1

        if [ $? -ne 0 ]; then

                CHECK=failed

                return

        fi

        CHECK=passed

}

#############################################################################

# OK, ready to start.

# Check if previous apcheck still running

# (may indicate 2 major problems - the previous apcheck failed unexpectedly,

# the 2nd one - the previous apcheck is delayed because of ping delays or

# something like this. Investigate, anyway.

if [ -f $LOCK ]; then

        report "Another copy of $0 is running!"

        exit 1

fi

# Create a lock-file with process ID

echo $$ > $LOCK

# First of all - check if the apdb's are OK

# AP db health is not our point here - so, we'll continue in either case.

if [ `$APCONFIG -D | $GREP Yes > /dev/null; echo $?` -eq 0 ]; then

        $APCONFIG -D > $DETAILS 2>&1

        report "AP database problems!"

fi

# Let's find out what the metainfo looks like

$APCONFIG -N > $METAINFO

# Find the active at the moment interface

ACTIVE=`$TAIL -$NICS $METAINFO | $AWK '$2 ~ /A/ { print $1 }'`

# Check the active interface - if OK, then finish silently

check $ACTIVE

# If check is failed - switch to the first passive interface, and test it.

if [ $CHECK = "failed" ]; then

        report "Active interface $ACTIVE check is failed!"

        SWITCHED=no

        # Remember that you may have more than one passive interface!

        # So, we will try to switch to all of them one-by-one, until

        # we found a good one. If all passive interfaces are failed -

        # switch back to the active one and scream!

        PASSIVE="`$TAIL -$NICS $METAINFO | $AWK '$2 !~ /A/ { print $1 }'`"

        GROUP=`$AWK '/metanetwork/ { print $2 }' $METAINFO`

        for INT in $PASSIVE; do

                $APCONFIG -P $GROUP -a $INT

                check $INT

                if [ $CHECK = "failed" ]; then

                        report "Alternate interface $INT check is failed!"

                        # Try another interface (if any)

                        continue

                fi

                report "Switched to alternate interface $INT!"

                SWITCHED=yes

                break

        done

        if [ $SWITCHED != "yes" ]; then

                # If we got here, then we having a serious problem -

                # None of alternate interfaces passed the check()

                # which means that all interfaces are down.

                # Report the problem, switch back to the active

                # interface and hope that network will be up soon.

                $APCONFIG -P $GROUP -a $ACTIVE

                echo "Switching back to the $ACTIVE interface." >> $DETAILS

                echo "The current configuration:" >> $DETAILS

                $APCONFIG -N >> $DETAILS

                echo "--------------------------" >> $DETAILS

                $APCONFIG -D >> $DETAILS

                report "Didn't find ANY working interfaces!"

        fi

fi

# We done.

$RM $METAINFO 2> /dev/null

$RM $DETAILS 2> /dev/null

$RM $LOCK 2> /dev/null

exit 0

##############################################################################

# Very ugly network picture

# /|\

# |

# ---------------

# | gateway |

# |----------| router |----------|

# | | 192.168.4.1 | |

# | --------------- |

# | |

# --------------- ---------------

# | switch | | switch |

# | 192.168.4.2 | | 192.168.4.3 |

# --------------- ---------------

# | --------------- |

# | | machine | |

# |------hme0| AP |qfe0------|

# | 192.168.4.4 |

# ---------------

#

##############################################################################

---------------------------CUT HERE------------------------------


--
Kins Orekhov
E-mail: kins@swoop.outlook.net
http://swoop.outlook.net

S
U BEFORE POSTING please READ the FAQ located at
N ftp://ftp.cs.toronto.edu/pub/jdd/sun-managers/faq
. and the list POLICY statement located at
M ftp://ftp.cs.toronto.edu/pub/jdd/sun-managers/policy
A To submit questions/summaries to this list send your email message to:
N sun-managers@codeprof.ececs.uc.edu
A To unsubscribe from this list please send an email message to:
G majordomo@codeprof.ececs.uc.edu
E and in the BODY type:
R unsubscribe sun-managers
S Or
. unsubscribe sun-managers original@subscription.address
L To view an archive of this list please visit:
I http://www.latech.edu/sunman.html
S
T

Comments

Got something to say?

You must be logged in to post a comment.