Page Menu
Home
ClusterLabs Projects
Search
Configure Global Search
Log In
Files
F2825003
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
13 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/heartbeat/.ocf-shellfuncs.in b/heartbeat/.ocf-shellfuncs.in
index 215b5592e..bfd5e7d0a 100644
--- a/heartbeat/.ocf-shellfuncs.in
+++ b/heartbeat/.ocf-shellfuncs.in
@@ -1,237 +1,244 @@
#
#
# Common helper functions for the OCF Resource Agents supplied by
# heartbeat.
#
# Copyright (c) 2004 SUSE LINUX AG, Lars Marowsky-Brée
# All Rights Reserved.
#
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# TODO: Some of this should probably split out into a generic OCF
# library for shell scripts, but for the time being, we'll just use it
# ourselves...
#
# TODO wish-list:
# - Generic function for evaluating version numbers
# - Generic function(s) to extract stuff from our own meta-data
# - Logging function which automatically adds resource identifier etc
# prefixes
# TODO: Move more common functionality for OCF RAs here.
#
# This was common throughout all legacy Heartbeat agents
unset LC_ALL; export LC_ALL
unset LANGUAGE; export LANGUAGE
__SCRIPT_NAME=`basename $0`
. @HA_HBCONF_DIR@/shellfuncs
if [ -z "$OCF_ROOT" ]; then
: ${OCF_ROOT=@OCF_ROOT_DIR@}
fi
. ${OCF_ROOT}/resource.d/heartbeat/.ocf-binaries
. ${OCF_ROOT}/resource.d/heartbeat/.ocf-returncodes
. ${OCF_ROOT}/resource.d/heartbeat/.ocf-directories
ocf_is_root() {
case `id` in
*'uid=0(root)'*) true;;
*) false;;
esac
}
ocf_maybe_random() {
local rnd="$RANDOM"
# Something sane-ish in case a shell doesn't support $RANDOM
[ -n "$rnd" ] || rnd=$$
echo $rnd
}
# Portability comments:
# o The following rely on Bourne "sh" pattern-matching, which is usually
# that for filename generation (note: not regexp).
# o The "*) true ;;" clause is probably unnecessary, but is included
# here for completeness.
# o The negation in the pattern uses "!". This seems to be common
# across many OSes (whereas the alternative "^" fails on some).
# o If an OS is encountered where this negation fails, then a possible
# alternative would be to replace the function contents by (e.g.):
# [ -z "`echo $1 | tr -d '[0-9]'`" ]
#
ocf_is_decimal() {
case "$1" in
""|*[!0-9]*) # empty, or at least one non-decimal
false ;;
*)
true ;;
esac
}
+ocf_is_true() {
+ case "$1" in
+ yes|true|1|YES|TRUE|ja|on|ON) true ;;
+ *) false ;;
+ esac
+}
+
ocf_is_hex() {
case "$1" in
""|*[!0-9a-fA-F]*) # empty, or at least one non-hex
false ;;
*)
true ;;
esac
}
ocf_is_octal() {
case "$1" in
""|*[!0-7]*) # empty, or at least one non-octal
false ;;
*)
true ;;
esac
}
__ocf_set_defaults() {
__OCF_ACTION="$1"
# Return to sanity for the agents...
unset LANG
LC_ALL=C
export LC_ALL
# TODO: Review whether we really should source this. Or rewrite
# to match some emerging helper function syntax...? This imports
# things which no OCF RA should be using...
# Strip the OCF_RESKEY_ prefix from this particular parameter
if [ -z "$OCF_RESKEY_OCF_CHECK_LEVEL" ]; then
: ${OCF_CHECK_LEVEL:=0}
else
: ${OCF_CHECK_LEVEL:=$OCF_RESKEY_OCF_CHECK_LEVEL}
fi
if [ ! -d "$OCF_ROOT" ]; then
ha_log "ERROR: OCF_ROOT points to non-directory $OCF_ROOT."
exit $OCF_ERR_GENERIC
fi
if [ -z "$OCF_RESOURCE_TYPE" ]; then
: ${OCF_RESOURCE_TYPE:=$__SCRIPT_NAME}
fi
if [ -z "$OCF_RA_VERSION_MAJOR" ]; then
: We are being invoked as an init script.
: Fill in some things with reasonable values.
: ${OCF_RESOURCE_INSTANCE:="default"}
return 0
fi
if [ "x$__OCF_ACTION" = "xmeta-data" ]; then
OCF_RESOURCE_INSTANCE="undef"
fi
if [ -z "$OCF_RESOURCE_INSTANCE" ]; then
ha_log "ERROR: Need to tell us our resource instance name."
exit $OCF_ERR_ARGS
fi
}
ocf_log() {
# TODO: Revisit and implement internally.
if
[ $# -lt 2 ]
then
ocf_log err "Not enough arguments [$#] to ocf_log."
fi
__OCF_PRIO="$1"
shift
__OCF_MSG="$*"
case "${__OCF_PRIO}" in
crit) __OCF_PRIO="CRIT";;
err) __OCF_PRIO="ERROR";;
warn) __OCF_PRIO="WARNING";;
info) __OCF_PRIO="INFO";;
debug)__OCF_PRIO="DEBUG";;
*) __OCF_PRIO=`echo ${__OCF_PRIO}| tr '[a-z]' '[A-Z]'`;;
esac
if [ "${__OCF_PRIO}" = "DEBUG" ]; then
ha_debug "${__OCF_PRIO}: $__OCF_MSG"
else
ha_log "${__OCF_PRIO}: $__OCF_MSG"
fi
}
#
# Ocf_run: Run a script, and log its output.
# Usage: ocf_run <command>
#
ocf_run() {
output=`"$@" 2>&1`
rc=$?
output=`echo $output`
if [ $rc -eq 0 ]; then
if [ ! -z "$output" ]; then
ocf_log info "$output"
fi
return $OCF_SUCCESS
else
if [ ! -z "$output" ]; then
ocf_log err "$output"
else
ocf_log err "command failed: $*"
fi
return $OCF_ERR_GENERIC
fi
}
ocf_pidfile_status() {
pidfile=$1
if [ ! -e $pidfile ]; then
# Not exists
return 2
fi
pid=`cat $pidfile`
kill -0 $pid 2>&1 > /dev/null
if [ $? = 0 ]; then
return 0
fi
# Stale
return 1
}
ocf_take_lock() {
local lockfile=$1
local rnd=$(ocf_maybe_random)
sleep 0.$rnd
while
ocf_pidfile_status $lockfile
do
ocf_log info "Sleeping until $lockfile is released..."
sleep 0.$rnd
done
echo $$ > $lockfile
}
ocf_release_lock_on_exit() {
lockfile=$1
trap "rm -f $lockfile" EXIT
}
__ocf_set_defaults "$@"
diff --git a/heartbeat/LVM b/heartbeat/LVM
index 31eab298a..4a25763b1 100644
--- a/heartbeat/LVM
+++ b/heartbeat/LVM
@@ -1,346 +1,353 @@
#!/bin/sh
#
#
# LVM
#
# Description: Manages an LVM volume as an HA resource
#
#
# Author: Alan Robertson
# Support: linux-ha@lists.linux-ha.org
# License: GNU General Public License (GPL)
# Copyright: (C) 2002 - 2005 International Business Machines, Inc.
#
# This code significantly inspired by the LVM resource
# in FailSafe by Lars Marowsky-Bree
#
#
# An example usage in /etc/ha.d/haresources:
# node1 10.0.0.170 ServeRAID::1::1 LVM::myvolname
#
# See usage() function below for more details...
#
# OCF parameters are as below:
# OCF_RESKEY_volgrpname
#
#######################################################################
# Initialization:
. ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs
#######################################################################
usage() {
methods=`LVM_methods`
methods=`echo $methods | tr ' ' '|'`
cat <<-!
usage: $0 $methods
$0 manages an Linux Volume Manager volume (LVM) as an HA resource
The 'start' operation brings the given volume online
The 'stop' operation takes the given volume offline
The 'status' operation reports whether the volume is available
The 'monitor' operation reports whether the volume seems present
The 'validate-all' operation checks whether the OCF parameters are valid
The 'methods' operation reports on the methods $0 supports
!
exit $OCF_ERR_GENERIC
}
meta_data() {
cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="LVM">
<version>1.0</version>
<longdesc lang="en">
Resource script for LVM. It manages an Linux Volume Manager volume (LVM)
as an HA resource.
</longdesc>
<shortdesc lang="en">LVM resource agent</shortdesc>
<parameters>
<parameter name="volgrpname" unique="0" required="1">
<longdesc lang="en">
The name of volume group.
</longdesc>
<shortdesc lang="en">Volume group name</shortdesc>
<content type="string" default="" />
</parameter>
+<parameter name="exclusive" unique="0" required="0">
+<longdesc lang="en">
+If set, the volume group will be activated exclusively.
+</longdesc>
+<shortdesc lang="en">Exclusive activation</shortdesc>
+<content type="string" default="false" />
+</parameter>
</parameters>
<actions>
<action name="start" timeout="30" />
<action name="stop" timeout="30" />
<action name="status" timeout="30" />
<action name="monitor" depth="0" timeout="30" interval="10" start-delay="10" />
<action name="methods" timeout="5" />
<action name="meta-data" timeout="5" />
<action name="validate-all" timeout="5" />
</actions>
</resource-agent>
END
}
#
# methods: What methods/operations do we support?
#
LVM_methods() {
cat <<-!
start
stop
status
monitor
methods
validate-all
usage
!
}
#
# Return LVM status (silently)
#
LVM_status() {
if
[ "$LVM_MAJOR" -eq "1" ]
then
vgdisplay $1 | grep -i 'Status.*available' >/dev/null
return $?
else
vgdisplay -v $1 | grep -i 'Status[ \t]*available' >/dev/null
return $?
fi
}
#
# Report on LVM volume status to stdout...
#
LVM_report_status() {
if
[ "$LVM_MAJOR" -eq "1" ]
then
VGOUT=`vgdisplay $1 2>&1`
echo "$VGOUT" | grep -i 'Status.*available' >/dev/null
rc=$?
else
VGOUT=`vgdisplay -v $1 2>&1`
echo "$VGOUT" | grep -i 'Status[ \t]*available' >/dev/null
rc=$?
fi
if
[ $rc -eq 0 ]
then
: Volume $1 is available
else
ocf_log debug "LVM Volume $1 is not available (stopped)"
return $OCF_NOT_RUNNING
fi
if
echo "$VGOUT" | grep -i 'Access.*read/write' >/dev/null
then
ocf_log debug "Volume $1 is available read/write (running)"
else
ocf_log debug "Volume $1 is available read-only (running)"
fi
return $OCF_SUCCESS
}
#
# Monitor the volume - does it really seem to be working?
#
#
LVM_monitor() {
if
LVM_status $1
then
: OK
else
ocf_log info "LVM Volume $1 is offline"
return $OCF_NOT_RUNNING
fi
ocf_run vgck $1
return $?
}
#
# Enable LVM volume
#
LVM_start() {
# TODO: This MUST run vgimport as well
ocf_log info "Activating volume group $1"
- if
- [ "$LVM_MAJOR" -eq "1" ]
- then
+ if [ "$LVM_MAJOR" -eq "1" ]; then
ocf_run vgscan $1
else
ocf_run vgscan
fi
- # TODO: For v2, this MUST use --refresh
- ocf_run vgchange -a y $1 || return $OCF_ERR_GENERIC
+ active_mode="y"
+ if ocf_is_true "$OCF_RESKEY_exclusive" ; then
+ active_mode="ey"
+ fi
- if
- LVM_status $1
- then
+ ocf_run vgchange -a $active_mode $1 || return $OCF_ERR_GENERIC
+
+ if LVM_status $1; then
: OK Volume $1 activated just fine!
return $OCF_SUCCESS
else
ocf_log err "LVM: $1 did not activate correctly"
return $OCF_ERR_GENERIC
fi
}
#
# Disable the LVM volume
#
LVM_stop() {
vgdisplay "$1" 2>&1 | grep 'Volume group .* not found' >/dev/null && {
ocf_log info "Volume group $1 not found"
return 0
}
ocf_log info "Deactivating volume group $1"
ocf_run vgchange -a n $1 || return 1
if
LVM_status $1
then
ocf_log err "LVM: $1 did not stop correctly"
return $OCF_ERR_GENERIC
fi
# TODO: This MUST run vgexport as well
return $OCF_SUCCESS
}
#
# Check whether the OCF instance parameters are valid
#
LVM_validate_all() {
check_binary $AWK
# Off-the-shelf tests...
vgck "$VOLUME" >/dev/null 2>&1
if [ $? -ne 0 ]; then
ocf_log err "Volume group [$VOLUME] does not exist or contains error!"
exit $OCF_ERR_GENERIC
fi
# Double-check
if
[ "$LVM_MAJOR" -eq "1" ]
then
vgdisplay "$VOLUME" >/dev/null 2>&1
else
vgdisplay -v "$VOLUME" >/dev/null 2>&1
fi
if [ $? -ne 0 ]; then
ocf_log err "Volume group [$VOLUME] does not exist or contains error!"
exit $OCF_ERR_GENERIC
fi
return $OCF_SUCCESS
}
#
# 'main' starts here...
#
if
( [ $# -ne 1 ] )
then
usage
exit $OCF_ERR_ARGS
fi
case $1 in
meta-data) meta_data
exit $OCF_SUCCESS;;
methods) LVM_methods
exit $?;;
usage) usage
exit $OCF_SUCCESS;;
*) ;;
esac
if
[ -z "$OCF_RESKEY_volgrpname" ]
then
# echo "You must identify the volume group name!"
ocf_log err "You must identify the volume group name!"
# usage
exit $OCF_ERR_ARGS
fi
# Get the LVM version number, for this to work we assume(thanks to panjiam):
#
# LVM1 outputs like this
#
# # vgchange --version
# vgchange: Logical Volume Manager 1.0.3
# Heinz Mauelshagen, Sistina Software 19/02/2002 (IOP 10)
#
# LVM2 and higher versions output in this format
#
# # vgchange --version
# LVM version: 2.00.15 (2004-04-19)
# Library version: 1.00.09-ioctl (2004-03-31)
# Driver version: 4.1.0
LVM_VERSION=`vgchange --version 2>&1 | \
$AWK '/Logical Volume Manager/ {print $5"\n"; exit; }
/LVM version:/ {printf $3"\n"; exit;}'`
rc=$?
if
( [ $rc -ne 0 ] || [ -z "$LVM_VERSION" ] )
then
ocf_log err "LVM: $1 could not determine LVM version. Try 'vgchange --version' manually and modify $0 ?"
exit $OCF_ERR_INSTALLED
fi
LVM_MAJOR="${LVM_VERSION%%.*}"
VOLUME=$OCF_RESKEY_volgrpname
# What kind of method was invoked?
case "$1" in
start) LVM_start $VOLUME
exit $?;;
stop) LVM_stop $VOLUME
exit $?;;
status) LVM_report_status $VOLUME
exit $?;;
monitor) LVM_monitor $VOLUME
exit $?;;
validate-all) LVM_validate_all
;;
*) usage
exit $OCF_ERR_AEGS;;
esac
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Jan 25, 11:10 AM (1 d, 7 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1322291
Default Alt Text
(13 KB)
Attached To
Mode
rR Resource Agents
Attached
Detach File
Event Timeline
Log In to Comment