Zionetrix::Git
Repositories
Help
Report an Issue
heartbeat_RouteVia
Code
Commits
Branches
Tags
Search
Tree:
0237c04
Branches
Tags
master
heartbeat_RouteVia
RouteVia
Inital commit
Benjamin Renard
commited
0237c04
at 2011-10-27 11:39:59
RouteVia
Blame
History
Raw
#!/bin/bash # # # Description: wrapper of OCF RA Route, based on original heartbeat RA. # See OCF RA Route for more information. # # Author: Benjamin Renard <brenard@easter-eggs.com> # License: GNU General Public License (GPL) # Copyright: (C) 2011 Easter-eggs # # This script manages IP route via a gateway # # It can add an IP route, or remove one. # # usage: $0 ip-network-destination/netmaskbits/ip-gateway \ # {start|stop|status|monitor} # # The "start" arg adds an IP route. # # The "stop" arg removes one. # DEBUG=0 function usage { echo "Usage : $0 [-h|--help] route/cidr/via {start|stop|status}" } [ "$1" == "-h" -o "$1" == "--help" ] && usage && exit 0 config=$1 function verif_ip { ip="$1" [ ! -n "$ip" ] && return 1 [ "$( echo -n "$ip"|sed "s/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*//" )" != "" ] && return 1 o1=$( echo "$ip"|cut -d'.' -f1 ) [ "$o1" == "" ] && return 2 [ $o1 -gt 254 ] && return 2 o2=$( echo "$ip"|cut -d'.' -f2 ) [ "$o2" == "" ] && return 3 [ $o2 -gt 254 ] && return 3 o3=$( echo "$ip"|cut -d'.' -f3 ) [ "$o3" == "" ] && return 4 [ $o3 -gt 254 ] && return 4 o4=$( echo "$ip"|cut -d'.' -f4 ) [ "$o4" == "" ] && return 5 [ $o4 -gt 254 ] && return 5 return 0 } function verif_cidr { cidr="$1" [ ! -n "$cidr" ] && return 1 [ "$( echo -n "$cidr"|sed 's/[0-9]*//' )" != '' ] && return 2 [ $cidr -gt 32 ] && return 3 return 0 } . /etc/ha.d/resource.d//hto-mapfuncs # Route route=$( echo "$config"|cut -d'/' -f1 ) [ $DEBUG -eq 1 ] && echo "Route : $route" verif_ip "$route" res=$? [ $res -ne 0 ] && echo "[ERROR] Route is not valid" && usage && exit $res # CIDR cidr=$( echo "$config"|cut -d'/' -f2 ) [ $DEBUG -eq 1 ] && echo "CIDR : $cidr" verif_cidr "$cidr" res=$? [ $res -ne 0 ] && echo "[ERROR] CIDR is not valid" && usage && exit $res export OCF_RESKEY_destination="$route/$cidr" # Via via=$( echo "$config"|cut -d'/' -f3 ) [ $DEBUG -eq 1 ] && echo "Via : $via" verif_ip "$via" res=$? [ $res -ne 0 ] && echo "[ERROR] Via host is not valid" && usage && exit $res export OCF_RESKEY_gateway="$via" export OCF_TYPE=Route export OCF_RESOURCE_INSTANCE=${OCF_TYPE}_${OCF_RESKEY_destination}_${OCF_RESKEY_gateway} ra_execocf $2