Send Linux-ha-cvs mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://lists.community.tummy.com/mailman/listinfo/linux-ha-cvs
or, via email, send a message with subject or body 'help' to
[EMAIL PROTECTED]
You can reach the person managing the list at
[EMAIL PROTECTED]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Linux-ha-cvs digest..."
Today's Topics:
1. Linux-HA CVS: resources by andrew from
([email protected])
----------------------------------------------------------------------
Message: 1
Date: Mon, 14 Aug 2006 03:33:48 -0600 (MDT)
From: [email protected]
Subject: [Linux-ha-cvs] Linux-HA CVS: resources by andrew from
To: [EMAIL PROTECTED]
Message-ID: <[EMAIL PROTECTED]>
linux-ha CVS committal
Author : andrew
Host :
Project : linux-ha
Module : resources
Dir : linux-ha/resources/OCF
Modified Files:
IPaddr.in
Log Message:
Cleanup prompted by inability to add an IP in under 10s on a regular basis
- Fix indenting
- Remove dead code
- Remove evil code
- Better use of SYSTYPE switches
- Add required abstraction for BSD variants
- More efficient operation
- Use configured values when supplied
- Complain when configured values dont match the results of findif
- Move all validation to validate-all and only autmatically call it before
start
- Reduce unnecessary logging
- Do not use ping by default (do so only when OCF_CHECK_LEVEL > 0)
More to follow...
===================================================================
RCS file: /home/cvs/linux-ha/linux-ha/resources/OCF/IPaddr.in,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -3 -r1.48 -r1.49
--- IPaddr.in 9 Aug 2006 13:01:54 -0000 1.48
+++ IPaddr.in 14 Aug 2006 09:33:47 -0000 1.49
@@ -39,12 +39,17 @@
FINDIF=$HA_BIN/findif
VLDIR=$HA_VARRUNDIR/rsctmp/IPaddr
SENDARPPIDDIR=$HA_VARRUNDIR/rsctmp/send_arp
+SENDARPPIDFILE="$SENDARPPIDDIR/send_arp-$OCF_RESKEY_ip"
[EMAIL PROTECTED]@
USAGE="usage: $0 {start|stop|status|monitor|validate-all|meta-data}";
#######################################################################
-LC_ALL=C
-export LC_ALL
+
+# Prevent ifconfig localization issues
+unset LC_ALL; export LC_ALL
+unset LANGUAGE; export LANGUAGE
+LC_ALL=C; export LC_ALL
+LC_MESSAGES=C; export LC_MESSAGES
[EMAIL PROTECTED]@/ha.d
. ${HA_D}/shellfuncs
@@ -204,104 +209,58 @@
exit $OCF_SUCCESS
}
-ip_init() {
- if
- case $__OCF_ACTION in
- start|stop) ocf_is_root;;
- *) true;;
- esac
- then
- : YAY!
- else
- ocf_log err "You must be root for $__OCF_ACTION operation."
- exit $OCF_ERR_PERM
- fi
- case $OCF_RESKEY_ip in
- "") ocf_log err "Required parameter OCF_RESKEY_ip is missing"
- exit $OCF_ERR_CONFIGURED;;
- [0-9]*.*.*.*[0-9]) : OK;;
- *) ocf_log err "Parameter OCF_RESKEY_ip [$OCF_RESKEY_ip] not an IP
address"
- exit $OCF_ERR_CONFIGURED;;
- esac
- case $__OCF_ACTION in
-
- start)
-
- IFCMD="$FINDIF -C $OCF_RESKEY_ip"
- #
- # $FINDIF can NOT deal with the condition of empty intermediate
parameters.
- #
- if
- [ ! -z "$OCF_RESKEY_netmask" -a -z "$OCF_RESKEY_cidr_netmask"
]
- then
- OCF_RESKEY_cidr_netmask=$OCF_RESKEY_netmask
- fi
- IFCMD="$FINDIF -C $OCF_RESKEY_ip"
- if
- [ -n "$OCF_RESKEY_cidr_netmask" ]
- then
- IFCMD="$IFCMD/$OCF_RESKEY_cidr_netmask"
- if
- [ -n "$OCF_RESKEY_nic" ]
- then
- IFCMD="$IFCMD/$OCF_RESKEY_nic"
- if
- [ -n "$OCF_RESKEY_broadcast" ]
- then
- IFCMD="$IFCMD/$OCF_RESKEY_broadcast"
- fi
- fi
- fi
-
- NICINFO=`$IFCMD`
- rc=$?
-
- if
- [ $rc -eq 0 ]
- then
- OCF_RESKEY_nic=`echo "$NICINFO" | cut -f1`
- OCF_RESKEY_cidr_netmask=`echo "$NICINFO" | cut -f2 | cut -d '
' -f2`
- OCF_RESKEY_broadcast=`echo "$NICINFO" | cut -f3 | cut -d ' '
-f2`
- else
- ocf_log err "$IFCMD failed [$rc]."
- exit $OCF_ERR_GENERIC
- fi
- ;;
- esac
-
- LVS_SUPPORT=0
- if [ "$SYSTYPE" = "Linux" -o "$SYSTYPE" = "SunOS" ]; then
- if [ x"${OCF_RESKEY_lvs_support}" = x"true" \
- -o x"${OCF_RESKEY_lvs_support}" = x"on" \
- -o x"${OCF_RESKEY_lvs_support}" = x"1" ]; then
- LVS_SUPPORT=1
- fi
- fi
-
- # Set default values (can be overridden as parameters)
- : ${OCF_RESKEY_ARP_INTERVAL_MS=500}
- : ${OCF_RESKEY_ARP_REPEAT=10}
- : ${OCF_RESKEY_ARP_BACKGROUND=yes}
- : ${OCF_RESKEY_ARP_NETMASK=ffffffffffff}
-
- SENDARPPIDFILE="$SENDARPPIDDIR/send_arp-$OCF_RESKEY_ip"
-
- case $OCF_RESKEY_nic in
- *:*)
- OCF_RESKEY_nic=`echo $OCF_RESKEY_nic | sed 's/:.*//'`
- ;;
- esac
+# On Linux systems the (hidden) loopback interface may
+# conflict with the requested IP address. If so, this
+# unoriginal code will remove the offending loopback address
+# and save it in VLDIR so it can be added back in later
+# when the IPaddr is released.
+#
+lvs_remove_conflicting_loopback() {
+ ipaddr="$1"
+ ifname="$2"
- if
- [ -d "$VLDIR/" ] || mkdir -p "$VLDIR/"
+ ocf_log info "Removing conflicting loopback $ifname."
+ if
+ echo $ifname > "$VLDIR/$ipaddr"
then
- : Directory $VLDIR now exists
+ : Saved loopback information in $VLDIR/$ipaddr
else
- ocf_log err "Could not create \"$VLDIR/\"."
- exit $OCF_ERR_GENERIC
+ ocf_log err "Could not save conflicting loopback $ifname." \
+ "it will not be restored."
fi
+ delete_interface "$ifname $ipaddr"
+
+ # Forcibly remove the route (if it exists) to the loopback.
+ delete_route "$ipaddr"
}
+#
+# On Linux systems the (hidden) loopback interface may
+# need to be restored if it has been taken down previously
+# by lvs_remove_conflicting_loopback()
+#
+lvs_restore_loopback() {
+ ipaddr="$1"
+
+ if [ ! -s "$VLDIR/$ipaddr" ]; then
+ return
+ fi
+
+ ifname=`cat "$VLDIR/$ipaddr"`
+ ocf_log info "Restoring loopback IP Address $ipaddr on $ifname."
+
+ NICINFO=`$FINDIF $ipaddr/32/$ifname`
+ if [ $? -eq 0 ]; then
+ netmask_text=`echo "$NICINFO" | cut -f2`
+ broadcast=`echo "$NICINFO" | cut -f3`
+ else
+ echo "ERROR: $IFCMD failed (rc=$rc)"
+ exit $OCF_ERR_GENERIC
+ fi
+
+ add_interface "$ipaddr" "$ifname" "$ifname" $netmask_text $broadcast
+ rm -f "$VLDIR/$ipaddr"
+}
#
# Find out which alias serves the given IP address
@@ -341,6 +300,11 @@
return $OCF_ERR_GENERIC
}
+find_interface_bsd() {
+ #$IFCONFIG $IFCONFIG_A_OPT | grep "inet.*[: ]$OCF_RESKEY_ip "
+ $IFCONFIG | grep "$ipaddr" -B20 | grep "UP," | tail -n 1 | cut -d ":" -f 1
+}
+
#
# Find out which alias serves the given IP address
# The argument is an IP address, and its output
@@ -348,42 +312,32 @@
#
find_interface_generic() {
ipaddr="$1"
- $IFCONFIG $IFCONFIG_A_OPT |
- while read ifname linkstuff
- do
- : Read gave us ifname = $ifname
-
- read inet addr junk
- : Read gave us inet = $inet addr = $addr
-
- while
- read line && [ "X$line" != "X" ]
+ $IFCONFIG $IFCONFIG_A_OPT |
+ while read ifname linkstuff
do
- : Nothing
- done
-
- case $ifname in
- *:*) ;;
- *) continue;;
- esac
-
-
- case "$SYSTYPE" in
- *BSD)
- $IFCONFIG | grep "$ipaddr" -B20 | grep "UP," | tail -n 1 | cut
-d ":" -f 1
- return 0;;
- *)
- : "comparing $ipaddr to $addr (from ifconfig)"
- case $addr in
- addr:$ipaddr) echo $ifname; return $OCF_SUCCESS;;
- $ipaddr) echo $ifname; return $OCF_SUCCESS;;
- esac
- continue;;
- esac
-
-
- done
- return $OCF_ERR_GENERIC
+ : Read gave us ifname = $ifname
+
+ read inet addr junk
+ : Read gave us inet = $inet addr = $addr
+
+ while
+ read line && [ "X$line" != "X" ]
+ do
+ : Nothing
+ done
+
+ case $ifname in
+ *:*) ;;
+ *) continue;;
+ esac
+
+ : "comparing $ipaddr to $addr (from ifconfig)"
+ case $addr in
+ addr:$ipaddr) echo $ifname; return $OCF_SUCCESS;;
+ $ipaddr) echo $ifname; return $OCF_SUCCESS;;
+ esac
+ done
+ return $OCF_ERR_GENERIC
}
#
@@ -395,11 +349,11 @@
ipaddr="$1"
case "$SYSTYPE" in
SunOS)
- NIC=`find_interface_solaris $ipaddr`
- ;;
- *)
- NIC=`find_interface_generic $ipaddr`
- ;;
+ NIC=`find_interface_solaris $ipaddr`;;
+ *BSD)
+ NIC=`find_interface_bsd $ipaddr`;;
+ *)
+ NIC=`find_interface_generic $ipaddr`;;
esac
echo $NIC
@@ -415,39 +369,27 @@
NIC="$1"
if [ "X$NIC" = "X" ]; then
- ocf_log err "No interface found for $OCF_RESKEY_ip"
+ ocf_log err "No free interface found for $OCF_RESKEY_ip"
return $OCF_ERR_GENERIC;
fi
+ NICBASE="$VLDIR/$NIC"
+ touch "$NICBASE"
+
case "$SYSTYPE" in
*BSD)
echo $NIC;
return $OCF_SUCCESS;;
-
SunOS)
+ j=1
IFLIST=`$IFCONFIG $IFCONFIG_A_OPT | \
- grep "^$NIC:[0-9]" | sed 's%: .*%%'`
- ;;
+ grep "^$NIC:[0-9]" | sed 's%: .*%%'`;;
*)
+ j=0
IFLIST=`$IFCONFIG $IFCONFIG_A_OPT | \
grep "^$NIC:[0-9]" | sed 's% .*%%'`
- ;;
- esac
-
- IFLIST=" `echo $IFLIST` "
- NICBASE="$VLDIR/$NIC"
- touch "$NICBASE"
-
- case "$SYSTYPE" in
- SunOS)
- j=1
- ;;
- *)
- j=0
TRYADRCNT=`ls "${NICBASE}:"* 2>/dev/null | wc -w | tr -d ' '`
- if
- [ -f "${NICBASE}:${TRYADRCNT}" ]
- then
+ if [ -f "${NICBASE}:${TRYADRCNT}" ]; then
: OK
else
j="${TRYADRCNT}"
@@ -455,50 +397,37 @@
;;
esac
+ IFLIST=" `echo $IFLIST` "
while
[ $j -lt 512 ]
do
case $IFLIST in
- *" "$NIC:$j" "*) ;;
- *)
- NICLINK="$NICBASE:$j"
- if
- ln "$NICBASE" "$NICLINK" 2>/dev/null
- then
- echo "$NIC:$j"
- return $OCF_SUCCESS
- fi;;
+ *" "$NIC:$j" "*)
+ ;;
+ *)
+ NICLINK="$NICBASE:$j"
+ if
+ ln "$NICBASE" "$NICLINK" 2>/dev/null
+ then
+ echo "$NIC:$j"
+ return $OCF_SUCCESS
+ fi
+ ;;
esac
j=`expr $j + 1`
done
return $OCF_ERR_GENERIC
}
-#
-# This routine should handle any type of interface, but has only been
-# tested on ethernet-type NICs.
-#
-ifconfig2sendarp() {
- echo "$1" | sed "s%:%%g"
-}
-
delete_route () {
ipaddr="$1"
case "$SYSTYPE" in
- SunOS)
- CMD=""
- ;;
- *BSD)
- CMD="$ROUTE -n delete -host $ipaddr"
- ;;
-
- *)
- CMD="$ROUTE -n del -host $ipaddr"
- ;;
+ SunOS) return 0;;
+ *BSD) CMD="$ROUTE -n delete -host $ipaddr";;
+ *) CMD="$ROUTE -n del -host $ipaddr";;
esac
- ocf_log info "$CMD"
$CMD
return $?
@@ -514,18 +443,14 @@
CMD="$IFCONFIG $ifname unplumb"
else
CMD="$IFCONFIG $ifname 0 down"
- fi
- ;;
+ fi;;
*BSD)
- CMD="$IFCONFIG $ifname inet $ipaddr delete"
- ;;
+ CMD="$IFCONFIG $ifname inet $ipaddr delete";;
*)
- CMD="$IFCONFIG $ifname down"
- ;;
+ CMD="$IFCONFIG $ifname down";;
esac
- ocf_log info "$CMD"
$CMD
return $?
@@ -536,22 +461,15 @@
ipaddr="$1"
iface_base="$2"
iface="$3"
- netmask_bits="$4"
- netmask_text=""
+ netmask="$4"
broadcast="$5"
- IFCMD="$FINDIF $ipaddr/$netmask_bits/$iface_base/$broadcast"
- NICINFO=`$IFCMD`
-
- rc=$?
- if [ $? -eq 0 ]; then
- netmask_text=`echo "$NICINFO" | cut -f2`
- broadcast=`echo "$NICINFO" | cut -f3`
- else
- echo "ERROR: $IFCMD failed (rc=$rc)"
+ if [ $# != 5 ]; then
+ ocf_log err "Insufficient arguments to add_interface: $*"
+ exit $OCF_ERR_ARGS
fi
- case $SYSTYPE in
+ case "$SYSTYPE" in
SunOS)
if [ "$SYSVERSION" -ge 8 ] ; then
$IFCONFIG $iface plumb
@@ -572,63 +490,20 @@
*BSD)
# netmask is always set to 255.255.255.255 for an alias
- CMD="$IFCONFIG $iface inet $ipaddr netmask 255.255.255.255 alias"
- ;;
+ CMD="$IFCONFIG $iface inet $ipaddr netmask 255.255.255.255 alias";;
*)
- CMD="$IFCONFIG $iface $ipaddr $netmask_text $broadcast"
- ;;
+ CMD="$IFCONFIG $iface $ipaddr netmask $netmask broadcast $broadcast";;
esac
- ocf_log info "eval $CMD"
- eval $CMD
+ $CMD
rc=$?
if [ $rc != 0 ]; then
- echo "ERROR: eval $CMD failed (rc=$rc)"
+ echo "ERROR: $CMD failed (rc=$rc)"
fi
return $rc
}
-# On Linux systems the (hidden) loopback interface may
-# conflict with the requested IP address. If so, this
-# unoriginal code will remove the offending loopback address
-# and save it in VLDIR so it can be added back in later
-# when the IPaddr is released.
-#
-remove_conflicting_loopback() {
- ipaddr="$1"
- ifname="$2"
-
- ocf_log info "Removing conflicting loopback $ifname."
- if
- echo $ifname > "$VLDIR/$ipaddr"
- then
- : Saved loopback information in $VLDIR/$ipaddr
- else
- ocf_log err "Could not save conflicting loopback $ifname." \
- "it will not be restored."
- fi
- delete_interface "$ifname $ipaddr"
- # Forcibly remove the route (if it exists) to the loopback.
- delete_route "$ipaddr"
-}
-
-# On Linux systems the (hidden) loopback interface may
-# need to be restored if it has been taken down previously
-# by remove_conflicting_loopback()
-#
-restore_loopback() {
- ipaddr="$1"
-
- if [ -s "$VLDIR/$ipaddr" ]; then
- ifname=`cat "$VLDIR/$ipaddr"`
- ocf_log info "Restoring loopback IP Address " \
- "$ipaddr on $ifname."
- add_interface "$ipaddr" "$ifname" "$ifname" "32"
- rm -f "$VLDIR/$ipaddr"
- fi
-}
-
#
# Remove the IP alias for the requested IP address...
#
@@ -636,71 +511,45 @@
SENDARPPIDFILE="$SENDARPPIDDIR/send_arp-$OCF_RESKEY_ip"
NIC=`find_interface $OCF_RESKEY_ip`
+ : ${OCF_RESKEY_nic=$NIC}
- if test -f "$SENDARPPIDFILE"
- then
+ if [ x$NIC != x -a $OCF_RESKEY_nic != $NIC ]; then
+ ocf_log err "Attempt to remove $OCF_RESKEY_ip from an interface other
than the one supplied"
+ return $OCF_ERR_ARGS
+ fi
+
+ if [ -f "$SENDARPPIDFILE" ]; then
cat "$SENDARPPIDFILE" | xargs kill
rm -f "$SENDARPPIDFILE"
fi
- case $SYSTYPE in
- *BSD)
- if $IFCONFIG $IFCONFIG_A_OPT | \
- grep "inet.*[: ]$OCF_RESKEY_ip " >/dev/null 2>&1; then
- continue;
- else
- exit $OCF_SUCCESS
- fi;;
-
- Linux|SunOS)
- if [ -z "$NIC" ]; then
- : Requested interface not in use
- exit $OCF_SUCCESS
-
- elif [ ${LVS_SUPPORT} = 1 ]; then
- case $NIC in
- lo*)
- : Requested interface is on loopback
- exit $OCF_SUCCESS
- ;;
- esac
- fi;;
- *)
- if [ -z "$NIC" ]; then
- : Requested interface not in use
- exit $OCF_SUCCESS
- fi;;
- esac
+ if [ -z "$NIC" ]; then
+ : Requested interface not in use
+ return $OCF_SUCCESS
+ fi
- if [ ! -z "${OCF_RESKEY_local_stop_script}" ]; then
- if [ -x "${OCF_RESKEY_local_stop_script}" ]; then
- ${OCF_RESKEY_local_stop_script} $*
- fi
+ if [ ${OCF_RESKEY_lvs_support} = 1 ]; then
+ case $NIC in
+ lo*)
+ : Requested interface is on loopback
+ return $OCF_SUCCESS;;
+ esac
fi
delete_route "$OCF_RESKEY_ip"
delete_interface "$NIC $OCF_RESKEY_ip"
rc=$?
- case $SYSTYPE in
- *BSD) ;;
- Linux|SunOS)
- restore_loopback "$OCF_RESKEY_ip"
- # remove lock file...
- rm -f "$VLDIR/$NIC";;
-
- *) # remove lock file...
- rm -f "$VLDIR/$NIC";;
- esac
+ if [ ${OCF_RESKEY_lvs_support} = 1 ]; then
+ lvs_restore_loopback "$OCF_RESKEY_ip"
+ fi
- case $rc in
- 0)
- ocf_log info "IP Address $OCF_RESKEY_ip released"
- ;;
- *)
- ocf_log warn "IP Address $OCF_RESKEY_ip NOT released"
- ;;
- esac
+ # remove lock file...
+ rm -f "$VLDIR/$NIC"
+
+ if [ $rc != 0 ]; then
+ ocf_log warn "IP Address $OCF_RESKEY_ip NOT released"
+ fi
return $rc
}
@@ -717,82 +566,73 @@
# Do we already service this IP address?
#
ip_status_internal
- rc=$?
-
- if [ $rc = $OCF_SUCCESS ]; then
- exit $OCF_SUCCESS;
+ if [ $? = $OCF_SUCCESS ]; then
+ # Nothing to do, the IP is already active
+ return $OCF_SUCCESS;
fi
- NIC_current=`find_interface $OCF_RESKEY_ip`
- NIC_unique=`find_free_interface $OCF_RESKEY_nic`
- SENDARPPIDFILE="$SENDARPPIDDIR/send_arp-$OCF_RESKEY_ip"
+ NIC_unique=`find_free_interface $OCF_RESKEY_nic`
if [ -n "$NIC_unique" ]; then
: OK got interface [$NIC_unique] for $OCF_RESKEY_ip
else
- exit $OCF_ERR_GENERIC
+ return $OCF_ERR_GENERIC
fi
# This logic is mostly to support LVS (If I understand it correctly)
- if [ ${LVS_SUPPORT} = 1 ]; then
+ if [ ${OCF_RESKEY_lvs_support} = 1 ]; then
+ NIC_current=`find_interface $OCF_RESKEY_ip`
case $NIC_unique in
lo*)
if [ x"$NIC_unique" = x"$NIC_current" ]; then
# Its already "running" and not moving, nothing to do.
ocf_log err "Could not find a non-loopback device to move
$OCF_RESKEY_ip to"
- exit $OCF_ERR_GENERIC
+ return $OCF_ERR_GENERIC
fi;;
- *) remove_conflicting_loopback "$OCF_RESKEY_ip" "$NIC_current";;
+ *) lvs_remove_conflicting_loopback "$OCF_RESKEY_ip"
"$NIC_current";;
esac
fi
- if [ ! -z "${OCF_RESKEY_local_start_script}" ]; then
- if [ -x "${OCF_RESKEY_local_start_script}" ]; then
- ${OCF_RESKEY_local_start_script} $*
- fi
- fi
-
+
add_interface "$OCF_RESKEY_ip" "$OCF_RESKEY_nic" "$NIC_unique" \
"$OCF_RESKEY_cidr_netmask" "$OCF_RESKEY_broadcast"
rc=$?
if [ $rc != 0 ]; then
+ ocf_log err "Could not add $OCF_RESKEY_ip to $OCF_RESKEY_nic: $rc"
return $rc
fi
-
- TARGET_INTERFACE=`echo $NIC_unique | sed 's%:.*%%'`
- if [ $SYSTYPE = "DarwinBSD" -a "$NIC_unique" = "lo0" ]; then
+ # The address is active, now notify others about it using sendarp
+
+ if [ "$SYSTYPE" = "DarwinBSD" -a "$NIC_unique" = "lo0" ]; then
# Darwin can't send ARPs on loopback devices
- SENDARP="echo $SENDARP"
+ SENDARP=""
fi
- ocf_log info "Sending Gratuitous Arp for $OCF_RESKEY_ip on $NIC_unique
[$TARGET_INTERFACE]"
-
- ARGS="-i $OCF_RESKEY_ARP_INTERVAL_MS -r $OCF_RESKEY_ARP_REPEAT"
- ARGS="$ARGS -p $SENDARPPIDFILE $TARGET_INTERFACE $OCF_RESKEY_ip"
- ARGS="$ARGS auto $OCF_RESKEY_ip $OCF_RESKEY_ARP_NETMASK"
- ocf_log info "$SENDARP $ARGS"
- case $OCF_RESKEY_ARP_BACKGROUND in
- yes) ($SENDARP $ARGS || ocf_log err "Could not send gratuitous arps.
rc=$?" & ) >&2 ;;
- *) $SENDARP $ARGS || ocf_log err "Could not send gratuitous arps.
rc=$?";;
- esac
-
- for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
- do
- ip_monitor
- if [ $? = $OCF_SUCCESS -o $? = $OCF_RUNNING_MASTER ]; then
- return $OCF_SUCCESS
- fi
- sleep 1
- done
- return $OCF_ERR_GENERIC
-}
+ if [ x$SENDARP != x ]; then
+ TARGET_INTERFACE=`echo $NIC_unique | sed 's%:.*%%'`
+ SENDARPPIDFILE="$SENDARPPIDDIR/send_arp-$OCF_RESKEY_ip"
+
+ ARGS="-i $OCF_RESKEY_ARP_INTERVAL_MS -r $OCF_RESKEY_ARP_REPEAT"
+ ARGS="$ARGS -p $SENDARPPIDFILE $TARGET_INTERFACE $OCF_RESKEY_ip"
+ ARGS="$ARGS auto $OCF_RESKEY_ip $OCF_RESKEY_ARP_NETMASK"
+
+ ocf_log debug "Sending Gratuitous Arp for $OCF_RESKEY_ip on $NIC_unique
[$TARGET_INTERFACE]"
+ case $OCF_RESKEY_ARP_BACKGROUND in
+ yes) ($SENDARP $ARGS || ocf_log err "Could not send gratuitous
arps. rc=$?" & ) >&2 ;;
+ *) $SENDARP $ARGS || ocf_log err "Could not send gratuitous arps.
rc=$?";;
+ esac
+ fi
+ ip_status_internal
+ return $?
+}
ip_status_internal() {
-
NIC=`find_interface "$OCF_RESKEY_ip"`
- if [ -z "$NIC" ]; then
+
+ if [ "x$NIC" = x ]; then
return $OCF_NOT_RUNNING
- elif [ ${LVS_SUPPORT} = 1 ]; then
+
+ elif [ "${OCF_RESKEY_lvs_support}" = "1" ]; then
case $NIC in
lo*) return $OCF_NOT_RUNNING;;
*) return $OCF_SUCCESS;;
@@ -820,103 +660,181 @@
# Note that we must distinguish if *we're* serving it locally...
#
ip_monitor() {
- TIMEOUT=1 # seconds
-
- ip_status_internal
- if [ $? = $OCF_NOT_RUNNING ]; then
- return $OCF_NOT_RUNNING
- fi
+ ip_status_internal
+ rc=$?
- case $SYSTYPE in
+ if [ $OCF_CHECK_LEVEL = 0 -o $rc != 0 ]; then
+ return $rc
+ fi
+
+ case "$SYSTYPE" in
Linux)
# -c count -t timetolive -q(uiet) -n(umeric) -W timeout
- PINGARGS="-c 1 -q -n $OCF_RESKEY_ip"
- ;;
+ PINGARGS="-c 1 -q -n $OCF_RESKEY_ip"
+ ;;
SunOS)
- PINGARGS="$OCF_RESKEY_ip $TIMEOUT"
- ;;
+ PINGARGS="$OCF_RESKEY_ip $TIMEOUT"
+ ;;
*)
- PINGARGS="-c 1 -q $OCF_RESKEY_ip"
- ;;
- esac
-
- for j in 1 2 3; do
- if @PING@ $PINGARGS >/dev/null 2>&1 ; then
- return $OCF_SUCCESS
- fi
- done
-
- return $OCF_ERR_GENERIC
+ PINGARGS="-c 1 -q $OCF_RESKEY_ip"
+ ;;
+ esac
+
+ for j in 1 2 3 4 5 6 7 8 9 10; do
+ if @PING@ $PINGARGS >/dev/null 2>&1 ; then
+ return $OCF_SUCCESS
+ fi
+ done
+
+ return $OCF_ERR_GENERIC
}
is_positive_integer() {
- ocf_is_decimal $1 && [ $1 -ge 1 ]
+ ocf_is_decimal $1 && [ $1 -ge 1 ]
+ if [ $? = 0 ]; then
+ return 1
+ fi
+ return 0
}
ip_validate_all() {
-# $BASEIP, $NETMASK, $NIC and $BRDCAST have been checked within ip_init,
-# do not bother here.
+ : ${OCF_RESKEY_ARP_BACKGROUND=yes}
+ : ${OCF_RESKEY_ARP_NETMASK=ffffffffffff}
+ : ${OCF_RESKEY_ARP_INTERVAL_MS=500}
+ : ${OCF_RESKEY_ARP_REPEAT=10}
+
+ if
+ [ -d "$VLDIR/" ] || mkdir -p "$VLDIR/"
+ then
+ : Directory $VLDIR now exists
+ else
+ ocf_log err "Could not create \"$VLDIR/\"."
+ return $OCF_ERR_GENERIC
+ fi
-# No need to Check lvs_support.
+ if is_positive_integer $OCF_RESKEY_ARP_INTERVAL_MS
+ then
+ ocf_log err "Invalid parameter value: ARP_INTERVAL_MS
[$OCF_RESKEY_ARP_INTERVAL_MS]"
+ return $OCF_ERR_ARGS
+ fi
- if is_positive_integer $OCF_RESKEY_ARP_INTERVAL_MS; then
- :
- else
- ocf_log err "Invalid OCF_RESKEY_ARP_INTERVAL_MS
[$OCF_RESKEY_ARP_INTERVAL_MS]"
- exit $OCF_ERR_ARGS
- fi
+ if is_positive_integer $OCF_RESKEY_ARP_REPEAT
+ then
+ ocf_log err "Invalid parameter value: ARP_REPEAT
[$OCF_RESKEY_ARP_REPEAT]"
+ return $OCF_ERR_ARGS
+ fi
- if is_positive_integer $OCF_RESKEY_ARP_REPEAT; then
+ : ${OCF_RESKEY_lvs_support=0}
+ if [ "$SYSTYPE" = "Linux" -o "$SYSTYPE" = "SunOS" ]; then
:
- else
- ocf_log err "Invalid OCF_RESKEY_ARP_REPEAT [$OCF_RESKEY_ARP_REPEAT]"
- exit $OCF_ERR_ARGS
- fi
+ else
+ if [ "${OCF_RESKEY_lvs_support}" = "1" ]; then
+ ocf_log err "$SYSTYPE does not support LVS"
+ return $OCF_ERR_GENERIC
+ fi
+ fi
+
+ case $OCF_RESKEY_ip in
+ "") ocf_log err "Required parameter OCF_RESKEY_ip is missing"
+ return $OCF_ERR_CONFIGURED;;
+ [0-9]*.[0-9]*.[0-9]*.*[0-9]) : OK;;
+ *) ocf_log err "Parameter OCF_RESKEY_ip [$OCF_RESKEY_ip] not an IP
address"
+ return $OCF_ERR_CONFIGURED;;
+ esac
+
+ # Unconditionally do this?
+ case $OCF_RESKEY_nic in
+ *:*)
+ OCF_RESKEY_nic=`echo $OCF_RESKEY_nic | sed 's/:.*//'`
+ ;;
+ esac
+
+ if [ ! -z "$OCF_RESKEY_netmask" -a -z "$OCF_RESKEY_cidr_netmask" ]; then
+ OCF_RESKEY_cidr_netmask=$OCF_RESKEY_netmask
+ fi
+
+ #
+ # $FINDIF can NOT deal with the condition of empty intermediate
parameters.
+ #
+ IFCMD="$FINDIF -C $OCF_RESKEY_ip"
+ if [ -n "$OCF_RESKEY_cidr_netmask" ]; then
+ IFCMD="$IFCMD/$OCF_RESKEY_cidr_netmask"
+ if [ -n "$OCF_RESKEY_nic" ]; then
+ IFCMD="$IFCMD/$OCF_RESKEY_nic"
+ if [ -n "$OCF_RESKEY_broadcast" ]; then
+ IFCMD="$IFCMD/$OCF_RESKEY_broadcast"
+ fi
+ fi
+ fi
+
+ NICINFO=`$IFCMD`
+ rc=$?
-# No need to check OCF_RESKEY_ARP_BACKGROUND
-# No need to check OCF_RESKEY_ARP_NETMASK, since it is currently unused
-# No need to check OCF_RESKEY_local_start_script and
OCF_RESKEY_local_stop_script
+ if [ $rc != 0 ]; then
+ ocf_log err "$IFCMD failed [rc=$rc]."
+ return $OCF_ERR_GENERIC
+ fi
+
+ tmp=`echo "$NICINFO" | cut -f1`
+ if [ "x$OCF_RESKEY_nic" = "x" ]; then
+ ocf_log info "Using calculated nic for ${OCF_RESKEY_ip}: $tmp"
+ OCF_RESKEY_nic=$tmp
+
+ elif [ x$tmp != x${OCF_RESKEY_nic} ]; then
+ ocf_log err "Invalid parameter value: nic [$OCF_RESKEY_nic [Calculated
nic: $tmp]"
+ return $OCF_ERR_ARGS
+ fi
+
+ tmp=`echo "$NICINFO" | cut -f2 | cut -d ' ' -f2`
+ if [ "x$OCF_RESKEY_cidr_netmask" = "x" ]; then
+ ocf_log info "Using calculated cidr netmask for ${OCF_RESKEY_ip}: $tmp"
+ OCF_RESKEY_cidr_netmask=$tmp
+
+ elif [ x$tmp != x${OCF_RESKEY_cidr_netmask} ]; then
+ ocf_log err "Invalid parameter value: netmask [$OCF_RESKEY_cidr_netmask
[Calculated netmask: $tmp]"
+ return $OCF_ERR_ARGS
+ fi
+
+ tmp=`echo "$NICINFO" | cut -f3 | cut -d ' ' -f2`
+ if [ "x$OCF_RESKEY_broadcast" = "x" ]; then
+ ocf_log info "Using calculated broadcast for ${OCF_RESKEY_ip}: $tmp"
+ OCF_RESKEY_broadcast=$tmp
+
+ elif [ x$tmp != x${OCF_RESKEY_broadcast} ]; then
+ ocf_log err "Invalid parameter value: broadcast [$OCF_RESKEY_broadcast
[Calculated broadcast: $tmp]"
+ return $OCF_ERR_ARGS
+ fi
+
return $OCF_SUCCESS
}
-
usage() {
- echo $USAGE >&2
+ echo $USAGE >&2
+ return $1
}
-#
-# Add or remove IP alias for the given IP address...
-#
-
-if
- [ $# -ne 1 ]
-then
- usage
- exit $OCF_ERR_ARGS
+if [ $# -ne 1 ]; then
+ usage $OCF_ERR_ARGS
fi
- case $1 in
- info) cat <<-!INFO
- Abstract=IP address takeover
- Argument=IP address OR IP address/broadcast address OR \\
- IP address/broadcast address/netmaskbits
- Description:
- An IPaddr resource is an IP address which is to be taken over by \\
- the owning node.
- Please rerun with the meta-data command for a list of \\
- valid arguments and their defaults.
- !INFO
- exit $OCF_SUCCESS;;
- esac
+: ${OCF_RESKEY_lvs_support=0}
+# Normalize the value of lvs_support
+if [ "${OCF_RESKEY_lvs_support}" = "true" \
+ -o "${OCF_RESKEY_lvs_support}" = "on" ]; then
+ OCF_RESKEY_lvs_support=1
+else
+ OCF_RESKEY_lvs_support=0
+fi
case $1 in
- meta-data) meta_data;;
- start) ip_init && ip_start;;
- stop) ip_init && ip_stop;;
- status) ip_init && ip_status;;
- monitor) ip_init && ip_monitor;;
- validate-all) ip_init && ip_validate_all;;
- usage) usage; exit $OCF_SUCCESS;;
- *) usage; exit $OCF_ERR_ARGS
- ;;
+ meta-data) meta_data;;
+ start) ip_validate_all && ip_start;;
+ stop) ip_stop;;
+ status) ip_status;;
+ monitor) ip_monitor;;
+ validate-all) ip_validate_all;;
+ usage) usage $OCF_SUCCESS;;
+ *) usage $OCF_ERR_UNIMPLEMENTED;;
esac
+
+exit $?
------------------------------
_______________________________________________
Linux-ha-cvs mailing list
[email protected]
http://lists.community.tummy.com/mailman/listinfo/linux-ha-cvs
End of Linux-ha-cvs Digest, Vol 33, Issue 24
********************************************