/usr/lib/ocf/resource.d/heartbeat/LVM is in cluster-agents 1:1.0.4-0ubuntu2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | #!/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_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
. ${OCF_FUNCTIONS_DIR}/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
!
}
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">Controls the availability of an LVM Volume Group</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>
<parameter name="partial_activation" unique="0" required="0">
<longdesc lang="en">
If set, the volume group will be activated even only partial of the physical
volumes available. It helps to set to true, when you are using mirroring
logical volumes.
</longdesc>
<shortdesc lang="en">Activate VG even with partial PV only</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" />
<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 2>&1 | grep -i 'Status.*available' 2>&1 >/dev/null
return $?
else
vgdisplay -v $1 2>&1 | grep -i 'Status[ \t]*available' 2>&1 >/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
vgck $1 >/dev/null 2>&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
ocf_run vgscan $1
else
ocf_run vgscan
fi
active_mode="ly"
if ocf_is_true "$OCF_RESKEY_exclusive" ; then
active_mode="ey"
fi
partial_active=""
if ocf_is_true "$OCF_RESKEY_partial_activation" ; then
partial_active="--partial"
fi
ocf_run vgchange -a $active_mode $partial_active $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_NOT_RUNNING
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 ln $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_CONFIGURED
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_UNIMPLEMENTED;;
esac
|