5 # Description: Manages an LVM2 volume group as an HA resource in
6 # an OCF-compliant cluster
9 # Authors: Alan Robertson, Lars Marowsky-Bree, Florian Haas,
10 # and others from the Linux-HA project
11 # License: GNU General Public License (GPL)
12 # Copyright: (C) 2002 - 2005 International Business Machines, Inc.
13 # (C) 2010 LINBIT HA-Solutions GmbH
15 # This code significantly inspired by the LVM resource
16 # in FailSafe by Lars Marowsky-Bree
18 #######################################################################
21 : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/resource.d/heartbeat}
22 .
${OCF_FUNCTIONS_DIR}/.ocf-shellfuncs
24 #######################################################################
28 methods
=`VolumeGroup_methods`
29 methods
=`echo $methods | tr ' ' '|'`
33 $0 manages an LVM Volume Group (VG) as an HA resource
35 The 'start' operation brings the given volume online
36 The 'stop' operation takes the given volume offline
37 The 'status' operation reports whether the volume is available
38 The 'monitor' operation reports whether the volume seems present
39 The 'validate-all' operation checks whether the OCF parameters are valid
40 The 'methods' operation reports on the methods $0 supports
48 <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
49 <resource-agent name="VolumeGroup">
50 <version>1.0</version>
53 Resource script for an LVM Volume Group.
55 <shortdesc lang="en">Controls the availability of an LVM Volume Group</shortdesc>
58 <parameter name="volgrpname" unique="0" required="1">
60 The name of volume group.
62 <shortdesc lang="en">Volume group name</shortdesc>
63 <content type="string" default="" />
65 <parameter name="exclusive" unique="0" required="0">
67 If set, the volume group will be activated exclusively.
69 <shortdesc lang="en">Exclusive activation</shortdesc>
70 <content type="boolean" default="false" />
75 <action name="start" timeout="30" />
76 <action name="stop" timeout="30" />
77 <action name="status" timeout="30" />
78 <action name="monitor" depth="0" timeout="30" interval="10" />
79 <action name="methods" timeout="5" />
80 <action name="meta-data" timeout="5" />
81 <action name="validate-all" timeout="5" />
88 # methods: What methods/operations do we support?
90 VolumeGroup_methods
() {
103 # Report on LVM volume status. VG may be reported as active
104 # ($OCF_SUCCESS) or inactive ($OCF_NOT_RUNNING)
106 VolumeGroup_status
() {
108 VGOUT
=`vgdisplay -v $OCF_RESKEY_volgrpname 2>&1` ||
exit $OCF_ERR_GENERIC
109 echo "$VGOUT" |
grep -i 'Status[ \t]*available' >/dev
/null
112 if [ $rc -eq 0 ]; then
113 ocf_log debug
"LVM Volume Group $OCF_RESKEY_volgrpname is available (started)"
115 ocf_log debug
"LVM Volume Group $OCF_RESKEY_volgrpname is not available (stopped)"
116 return $OCF_NOT_RUNNING
119 if echo "$VGOUT" |
grep -i 'Access.*read/write' >/dev
/null
; then
120 ocf_log debug
"Volume $OCF_RESKEY_volgrpname is available read/write (running)"
122 ocf_log debug
"Volume $OCF_RESKEY_volgrpname is available read-only (running)"
129 # Monitor the volume - does it really seem to be working? May report
130 # $OCF_SUCCESS or $OCF_NOT_RUNNING like VolumeGroup_status, plus
131 # $OCF_ERR_GENERIC in case vgck reports an error.
133 VolumeGroup_monitor
() {
134 if ! VolumeGroup_status
$OCF_RESKEY_volgrpname; then
135 ocf_log info
"LVM Volume Group $OCF_RESKEY_volgrpname is offline"
136 return $OCF_NOT_RUNNING
139 ocf_run vgck
$OCF_RESKEY_volgrpname ||
exit $OCF_ERR_GENERIC
145 # Activate the volume group, either locally (if $OCF_RESKEY_exclusive
146 # is false or unset), or exclusively (if $OCF_RESKEY_exclusive is
148 # Either returns successfully, or exits with $OCF_ERR_GENERIC.
150 VolumeGroup_start
() {
152 ocf_log info
"Activating volume group $OCF_RESKEY_volgrpname"
157 if ocf_is_true
"$OCF_RESKEY_exclusive" ; then
161 ocf_run vgchange
-a $active_mode $OCF_RESKEY_volgrpname ||
exit $OCF_ERR_GENERIC
163 if ! VolumeGroup_status
$OCF_RESKEY_volgrpname; then
164 ocf_log err
"LVM: $OCF_RESKEY_volgrpname did not activate correctly"
165 exit $OCF_ERR_GENERIC
172 # Deactivate the volume group.
173 # Either returns successfully, or exits with $OCF_ERR_GENERIC.
176 if ! VolumeGroup_status
; then
177 ocf_log debug
"Volume Group $OCF_RESKEY_volgrpname already stopped"
181 ocf_log info
"Deactivating volume group $OCF_RESKEY_volgrpname"
182 ocf_run vgchange
-a ln $OCF_RESKEY_volgrpname ||
exit $OCF_ERR_GENERIC
184 if VolumeGroup_status
; then
185 ocf_log err
"LVM: $OCF_RESKEY_volgrpname did not stop correctly"
186 exit $OCF_ERR_GENERIC
193 # Check whether the OCF instance parameters are valid.
194 # Either returns successfully, or exits with
195 # $OCF_ERR_CONFIGURED if required parameters are missing;
196 # $OCF_ERR_INSTALLED if required binaries are missing;
197 # $OCF_ERR_GENERIC in case of any other error.
199 VolumeGroup_validate_all
() {
201 if [ -z $OCF_RESKEY_volgrpname ]; then
202 ocf_log err
'Missing required parameter "volgrpname"!'
203 exit $OCF_ERR_CONFIGURED
206 check_binary vgchange
208 check_binary vgdisplay
210 # Run the following tests only if we're not invoked by a probe
212 if ! ocf_is_probe
; then
213 # Off-the-shelf tests...
214 vgck
"$OCF_RESKEY_volgrpname" >/dev
/null
2>&1
215 if [ $?
-ne 0 ]; then
216 ocf_log err
"Volume group $OCF_RESKEY_volgrpname does not exist or contains error!"
217 exit $OCF_ERR_GENERIC
221 vgdisplay
-v "$OCF_RESKEY_volgrpname" >/dev
/null
2>&1
222 if [ $?
-ne 0 ]; then
223 ocf_log err
"Volume group $OCF_RESKEY_volgrpname does not exist or contains error!"
224 exit $OCF_ERR_GENERIC
232 # 'main' starts here...
234 if [ $# -ne 1 ]; then
243 methods
) VolumeGroup_methods
251 # Everything except usage and meta-data must pass the validate test
252 VolumeGroup_validate_all
254 # What kind of method was invoked?
270 notify|promote|demote|migrate_from|migrate_to
)
272 exit $OCF_ERR_UNIMPLEMENTED