Sunny Simon - 2006-08-17

# Hi@All,
#
# We've created an script that is able to create
# more then one bond with differend options.
# So it is possible to create bond0 in
# active-backup-mode and bond1 ind
# load-balanced-mode.
# The intention for this script is a bug in RedHat # Enterprise Server 4, that seems to be unfixable # today.
# So we've tested this startscript only under
# RedHat ES 4.
#
# script follows:
# ------------------------------------------------

#!/bin/sh
# bondingload       Bring up/down bondingIF
#
# chkconfig: 2345 9 92
# description: starts bonding Interfaces bonding0(bond0) and bonding1(bond1)
#
#
### BEGIN INIT INFO
# Provides: $bondingload
### END INIT INFO

# This script loads the bonding Module with a different name cause of multiple use of bonding interfaces
#
# by:      Chris Hölzel / Maxpert  | Steffen Kaiser / COLT
# E-Mail:  chris.hoelzel@maxpert.de | steffen.kaiser@colt.net
#
# Version: 0.5
# Date:    17.08.2006
# Copyright by Maxpert 2006

#first we will declare variables for global use
b0islaod=0
b1isload=0
b0option="-o bonding0 bonding mode=1"
b1option="-o bonding1 bonding mode=1"
awk1=0
awk2=0

#function declaration for module-loading
loadb0() {
          echo "... load module bonding as bonding0"
          /sbin/modprobe $b0option
          return "1"
         }

#function declaration for module-loading
loadb1() {
          echo "... load module bonding as bonding1"
          /sbin/modprobe $b1option
          return "1"
         }
#read out, if module bonding1 is loaded and make if consense
statusb1() {
if [ "`lsmod | awk '/bonding1/ { print "1" }' $1`" = 1 ]
then
  echo "... module bonding1 is loaded"
  b1isload=1
else
  echo "... module bonding1 is not loaded"
  b1isload=0
fi

return $b1isload
}

deloadb0() {
        echo "... unloaded module bonding0"
        /sbin/rmmod bonding0
        return "1"
}
        fi
        ;;
status)
        statusb0
        statusb1
        ;;
*)
        echo $"Usage: $0 {start|stop|status|restart}"
        exit 1
esac

exit 0

deloadb1() {
        echo "... unloaded module bonding1"
        /sbin/rmmod bonding1
        return "1"
}

echo "This script controlls the bonding Modules ..."

case "$1" in
start)
        statusb0
        if [ $b0isload = 0 ]
        then
                loadb0
        fi

        statusb1
        if [ $b1isload = 0 ]
        then
                loadb1
        fi
        ;;
stop)

        statusb0
        if [ $b0isload = 1 ]
        then
                deloadb0
        fi

        statusb1
        if [ $b1isload = 1 ]
        then
                deloadb1
        fi
        ;;
restart)

        statusb0
        if [ $b0isload = 1 ]
        then
                deloadb0
        fi

        statusb1
        if [ $b1isload = 1 ]
        then
                deloadb1
        fi

        statusb0
        if [ $b0isload = 0 ]
        then
                loadb0
        fi

        statusb1
        if [ $b1isload = 0 ]
        then
                loadb1
        fi
        ;;
status)
        statusb0
        statusb1
        ;;
*)
        echo $"Usage: $0 {start|stop|status|restart}"
        exit 1
esac

exit 0

#------------------------------------------------
# Copy the script between the lines in a new
# (blank) file and save this file under
# /etc/init.d/bondingload
# So this is an servicescript which needs to be
# started before the network-startup-script.
# If you use RedHat you can then simply activate
# this script by "chkconfig bondingload on".
# You also need to edit the variables b0options
# and b1options for your needs.
# Please consult the bonding-Documentation for the # correct module-options.
# After starting this script it will load an
# module named bonding0 and one named bonding1.
# These are both the module bonding, but they are
# renamed in kernelspace. So it is possible to set # different options for the bonds.
# Then you have to edit the /etc/modprobe.conf or
# /etc/modules.conf.
# There you need a line like "alias bond0
# bonding0" and this is coherent for all bonds you
# whish to set.
# Last but not least you have to create
# ifcfg-bond0 and ifcfg-bond1 in
# /etc/sysconfig/network-scripts.
# These are the IP assignments for bond0 and
# bond1.
# You will also need ifcfg-ethX files, which
# descripe the interface to bond assignment.
# Here you can also consult the bonding
# documentation.
################################################
# Reglementation of this script:
# At version 0.5 - 17.08.2006 this script only
# supports 2 bonding-interfaces.
# If we would find more time to change this
# script, we will add support for N bonds.
# Please give us a little bit time.
################################################
# Nice speaking at the end:
# Important is only that what will leave us at the
# back.