I tested it on my deployment and it worked well when tested on
start-stop-status operations. I am using this script because I did not
have 3 IP addresses to allocate to a two node cluster. I used it in
combination with IPAddr2. It could be used to create a failover
capable routing device.

#!/bin/sh
#
# Author:      Edward Guy Capriolo
# License:      GNU General Public License (GPL)
# Date:         2007 June 12
#
#       Manages the default iproute. Could be used in a failover between
#       network links. This script uses iproute -n. Avoid hostnames and
#       the default keyword.
#
#       usage: $0  {start|stop|status|monitor|meta-data}
#
#         OCF parameters Required :
#               OCF_RESKEY_network
#               OCF_RESKEY_router
#

#######################################################################
# Initialization:

. /usr/lib64/heartbeat/ocf-shellfuncs

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


usage() {
 cat <<-!
       usage: $0 {start|stop|status|monitor|meta-data|validate-all}
       !
}

meta_data() {
       cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="iproute">
<version>1.0</version>

<longdesc lang="en">
Resource Agent for the linux routing table
</longdesc>
<shortdesc lang="en">iproute resource agent</shortdesc>

<parameters>

<parameter name="network" unique="0" required="1">
<longdesc lang="en">
The network to be routed
</longdesc>
<shortdesc lang="en">The network to be routed</shortdesc>
<content type="string" default="" />
</parameter>


<parameter name="router" unique="0" required="1">
<longdesc lang="en">
The ip to be routed to
</longdesc>
<shortdesc lang="en">The ip the routed network should be routed to</shortdesc>
<content type="string" default="" />
</parameter>

</parameters>

<actions>
<action name="start" timeout="5" />
<action name="stop" timeout="5" />
<action name="status" depth="0" timeout="5" interval="10" start-delay="5" />
<action name="monitor" depth="0" timeout="5" interval="10" start-delay="5" />
<action name="meta-data" timeout="5" />
<action name="validate-all" timeout="5" />
</actions>
</resource-agent>
END
}

iproute_status() {
 FIND_NET=`/sbin/route -n | grep $OCF_RESKEY_network`
 if [ "$FIND_NET" = "" ] ; then
       return $OCF_NOT_RUNNING
 else
       FIND_ROUTER=`echo $FIND_NET | grep $OCF_RESKEY_router`
       if [ "$FIND_ROUTER" = "" ] ; then
               return $OCF_NOT_RUNNING
       else
               return $OCF_SUCCESS
       fi
 fi
}

iproute_monitor() {
 iproute_status
}

iproute_start() {
 if
   iproute_status
 then
   ocf_log info "iproute $OCF_RESKEY_network - $OCF_RESKEY_router
already running"
   return $OCF_SUCCESS
 else
   /sbin/route add -net $OCF_RESKEY_network gw $OCF_RESKEY_router
   rc=$?
   if
     [ $rc -ne 0 ]
   then
     return $OCF_ERR_PERM
   else
     return $OCF_SUCCESS
   fi
 fi
}

iproute_stop() {
 if
   iproute_status
 then
   /sbin/route -n del -net $OCF_RESKEY_network gw $OCF_RESKEY_router
   rc=$?
   if
     [ $rc -ne 0 ]
   then
     return $OCF_ERR_PERM
   else
     return $OCF_SUCCESS
   fi
 else
   ocf_log info "iproute $OCF_RESKEY_network $OCF_RESKEY_router
already stopped"
   return $OCF_SUCCESS
 fi
}

iproute_validate_all() {
 return $OCF_SUCCESS
}

if [ $# -ne 1 ]; then
 usage
 exit $OCF_ERR_ARGS
fi

case $1 in
 meta-data)            meta_data
                       exit $OCF_SUCCESS
                       ;;
 start)                iproute_start
                       ;;
 stop)                 iproute_stop
                       ;;
 monitor)              iproute_monitor
                       ;;
 status)               iproute_monitor
                       ;;
 validate-all)         iproute_validate_all
                       ;;
 usage)                usage
                       exit $OCF_SUCCESS
                       ;;
 *)                    usage
                       exit $OCF_ERR_ARGS
                       ;;
esac
exit $?
_______________________________________________
Linux-HA mailing list
[email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha
See also: http://linux-ha.org/ReportingProblems

Reply via email to