4
# Author Matthias Dahl, m.dahl@designassembly.de
5
# License GPL version 2
7
# (c) 2006 The Design Assembly GmbH.
10
# WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
12
# This resource agent is most likely function complete but not error free. Please
13
# consider it BETA quality for the moment until it has proven itself stable...
15
# USE AT YOUR OWN RISK.
17
# WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
20
# partly based on/inspired by original Heartbeat2 OCF resource agents
24
# This OCF complaint resource agent manages OpenVZ VEs and thus requires
25
# a proper OpenVZ installation including a recent vzctl util.
28
# Created 07. Sep 2006
29
# Updated 18. Sep 2006
35
# 12/Sep/06 1.00.3 more cleanup
36
# 12/Sep/06 1.00.2 fixed some logic in start_ve
37
# general cleanup all over the place
38
# 11/Sep/06 1.00.1 fixed some typos
39
# 07/Sep/06 1.00.0 it's alive... muahaha... ALIVE... :-)
43
. ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs
52
# taken from Raid1 Heartbeat2 OCF resource agent
56
usage: $0 {start|stop|status|monitor|validate-all|usage|meta-data}
67
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
68
<resource-agent name="ManageVE">
69
<version>1.00.3</version>
72
This OCF complaint resource agent manages OpenVZ VEs and thus requires
73
a proper OpenVZ installation including a recent vzctl util.
76
<shortdesc lang="en">OpenVZ VE resource agent</shortdesc>
79
<parameter name="veid" unique="0" required="1">
81
OpenVZ ID of virtual environment (see output of vzlist -a for all assigned IDs)
83
<shortdesc lang="en">OpenVZ ID of VE</shortdesc>
84
<content type="integer" default="" />
89
<action name="start" timeout="75" />
90
<action name="stop" timeout="75" />
91
<action name="status" depth="0" timeout="10" interval="10" start-delay="0" />
92
<action name="monitor" depth="0" timeout="10" interval="10" start-delay="0" />
93
<action name="validate-all" timeout="5" />
94
<action name="meta-data" timeout="5" />
103
# ATTENTION: The following code relies on vzctl's exit codes, especially:
106
# 32 : VE already running
108
# In case any of those exit codes change, this function will need fixing.
114
veexists=`$VZCTL status $VEID 2>/dev/null | $AWK '{print $3}'`
115
if [[ $veexists != "exist" ]]; then
116
ocf_log err "vzctl status $VEID returned: $VEID does not exist."
117
return $OCF_ERR_INSTALLED
123
if [[ $retcode == $OCF_SUCCESS ]]; then
125
elif [[ $retcode != $OCF_NOT_RUNNING ]]; then
129
$VZCTL start $VEID >& /dev/null
132
if [[ $retcode != 0 && $retcode != 32 ]]; then
133
ocf_log err "vzctl start $VEID returned: $retcode"
134
return $OCF_ERR_GENERIC
143
# ATTENTION: The following code relies on vzctl's exit codes, especially:
147
# In case any of those exit codes change, this function will need fixing.
153
$VZCTL stop $VEID >& /dev/null
156
if [[ $retcode != 0 ]]; then
157
ocf_log err "vzctl stop $VEID returned: $retcode"
158
return $OCF_ERR_GENERIC
167
# ATTENTION: The following code relies on vzctl's status output. The fifth
168
# column is interpreted as the VE status (either up or down).
170
# In case the output format should change, this function will need fixing.
176
veexists=`$VZCTL status $VEID 2>/dev/null | $AWK '{print $3}'`
177
vestatus=`$VZCTL status $VEID 2>/dev/null | $AWK '{print $5}'`
180
if [[ $retcode != 0 ]]; then
181
ocf_log err "vzctl status $VEID returned: $retcode"
182
return $OCF_ERR_GENERIC
185
if [[ $veexists != "exist" ]]; then
186
ocf_log err "vzctl status $VEID returned: $VEID does not exist."
187
return $OCF_NOT_RUNNING
195
return $OCF_NOT_RUNNING
198
ocf_log err "vzctl status $VEID, wrong output format. (5th column: $vestatus)"
199
return $OCF_ERR_GENERIC
207
# ATTENTION: The following code relies on vzctl's status output. The fifth
208
# column is interpreted as the VE status (either up or down).
210
# In case the output format should change, this function will need fixing.
216
# VEID should be a valid VE
220
if [[ $retcode != $OCF_SUCCESS && $retcode != $OCF_NOT_RUNNING ]]; then
228
if [[ $# != 1 ]]; then
247
# check relevant environment variables for sanity and security
251
`test -z "$OCF_RESKEY_veid"`
253
declare -i veidtest1=$?
256
`echo "$OCF_RESKEY_veid" | egrep -q '^[[:digit:]]+$'`
258
if [[ $veidtest1 != 1 || $? != 0 ]]; then
259
ocf_log err "OCF_RESKEY_veid not set or not a number."
263
declare -i VEID=$OCF_RESKEY_veid
266
# check that all relevant utilities are available
272
# finally... let's see what we are ordered to do :-)
289
exit $OCF_ERR_UNIMPLEMENTED