~ampelbein/ubuntu/oneiric/heartbeat/lp-770743

« back to all changes in this revision

Viewing changes to resources/OCF/ManageVE

  • Committer: Bazaar Package Importer
  • Author(s): Ante Karamatic
  • Date: 2010-02-17 21:59:18 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20100217215918-06paxph5do4saw8v
Tags: 3.0.2-0ubuntu1
* New upstream release
* Drop hard dep on pacemaker for heartbet; moved to Recommends
* debian/heartbeat.install:
  - follow upstream changes
* debian/control:
  - added docbook-xsl and xsltproc to build depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
#
3
 
# Name     ManageVE
4
 
# Author   Matthias Dahl, m.dahl@designassembly.de
5
 
# License  GPL version 2
6
 
#
7
 
# (c) 2006 The Design Assembly GmbH.
8
 
#
9
 
#
10
 
# WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
11
 
#
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...
14
 
#
15
 
# USE AT YOUR OWN RISK.
16
 
#
17
 
# WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
18
 
#
19
 
#
20
 
# partly based on/inspired by original Heartbeat2 OCF resource agents
21
 
#
22
 
# Description
23
 
#
24
 
# This OCF complaint resource agent manages OpenVZ VEs and thus requires
25
 
# a proper OpenVZ installation including a recent vzctl util.
26
 
#
27
 
#
28
 
# Created  07. Sep 2006
29
 
# Updated  18. Sep 2006
30
 
#
31
 
# rev. 1.00.3
32
 
#
33
 
# Changelog
34
 
#
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... :-)
40
 
41
 
 
42
 
###
43
 
. ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs
44
 
###
45
 
 
46
 
# required utilities
47
 
VZCTL=/usr/sbin/vzctl
48
 
 
49
 
#
50
 
# usage()
51
 
#
52
 
# taken from Raid1 Heartbeat2 OCF resource agent
53
 
usage()
54
 
{
55
 
        cat <<-EOT
56
 
        usage: $0 {start|stop|status|monitor|validate-all|usage|meta-data}
57
 
        EOT
58
 
}
59
 
 
60
 
#
61
 
# meta_data()
62
 
#
63
 
meta_data()
64
 
{
65
 
        cat <<END
66
 
<?xml version="1.0"?>
67
 
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
68
 
<resource-agent name="ManageVE">
69
 
  <version>1.00.3</version>
70
 
 
71
 
  <longdesc lang="en">
72
 
    This OCF complaint resource agent manages OpenVZ VEs and thus requires
73
 
    a proper OpenVZ installation including a recent vzctl util.
74
 
  </longdesc>
75
 
 
76
 
  <shortdesc lang="en">OpenVZ VE resource agent</shortdesc>
77
 
 
78
 
  <parameters>
79
 
    <parameter name="veid" unique="0" required="1">
80
 
      <longdesc lang="en">
81
 
        OpenVZ ID of virtual environment (see output of vzlist -a for all assigned IDs)
82
 
      </longdesc>
83
 
      <shortdesc lang="en">OpenVZ ID of VE</shortdesc>
84
 
      <content type="integer" default="" />
85
 
    </parameter>
86
 
  </parameters>
87
 
 
88
 
  <actions>
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" />
95
 
  </actions>
96
 
</resource-agent>
97
 
END
98
 
}
99
 
 
100
 
#
101
 
# start_ve()
102
 
#
103
 
# ATTENTION: The following code relies on vzctl's exit codes, especially:
104
 
#
105
 
#   0 : success
106
 
#  32 : VE already running
107
 
#
108
 
# In case any of those exit codes change, this function will need fixing.
109
 
#
110
 
start_ve()
111
 
{
112
 
  declare -i retcode
113
 
 
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
118
 
  fi
119
 
 
120
 
  status_ve
121
 
  retcode=$?
122
 
 
123
 
  if [[ $retcode == $OCF_SUCCESS ]]; then
124
 
    return $OCF_SUCCESS
125
 
  elif [[ $retcode != $OCF_NOT_RUNNING ]]; then
126
 
    return $retcode
127
 
  fi
128
 
 
129
 
  $VZCTL start $VEID >& /dev/null
130
 
  retcode=$?
131
 
 
132
 
  if [[ $retcode != 0 && $retcode != 32 ]]; then
133
 
    ocf_log err "vzctl start $VEID returned: $retcode"
134
 
    return $OCF_ERR_GENERIC
135
 
  fi
136
 
 
137
 
  return $OCF_SUCCESS
138
 
}
139
 
 
140
 
#
141
 
# stop_ve()
142
 
#
143
 
# ATTENTION: The following code relies on vzctl's exit codes, especially:
144
 
#
145
 
#   0 : success
146
 
#
147
 
# In case any of those exit codes change, this function will need fixing.
148
 
#
149
 
stop_ve()
150
 
{
151
 
  declare -i retcode
152
 
 
153
 
  $VZCTL stop $VEID >& /dev/null
154
 
  retcode=$?
155
 
 
156
 
  if [[ $retcode != 0 ]]; then
157
 
    ocf_log err "vzctl stop $VEID returned: $retcode"
158
 
    return $OCF_ERR_GENERIC
159
 
  fi
160
 
 
161
 
  return $OCF_SUCCESS
162
 
}
163
 
 
164
 
#
165
 
# status_ve()
166
 
#
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).
169
 
#
170
 
# In case the output format should change, this function will need fixing.
171
 
#
172
 
status_ve()
173
 
174
 
  declare -i retcode
175
 
 
176
 
  veexists=`$VZCTL status $VEID 2>/dev/null | $AWK '{print $3}'`
177
 
  vestatus=`$VZCTL status $VEID 2>/dev/null | $AWK '{print $5}'`
178
 
  retcode=$?
179
 
 
180
 
  if [[ $retcode != 0 ]]; then
181
 
    ocf_log err "vzctl status $VEID returned: $retcode"
182
 
    return $OCF_ERR_GENERIC
183
 
  fi
184
 
 
185
 
  if [[ $veexists != "exist" ]]; then
186
 
    ocf_log err "vzctl status $VEID returned: $VEID does not exist."
187
 
    return $OCF_NOT_RUNNING
188
 
  fi
189
 
 
190
 
  case "$vestatus" in
191
 
    running)
192
 
        return $OCF_SUCCESS
193
 
        ;;
194
 
    down)
195
 
        return $OCF_NOT_RUNNING
196
 
        ;;
197
 
    *)
198
 
        ocf_log err "vzctl status $VEID, wrong output format. (5th column: $vestatus)"
199
 
        return $OCF_ERR_GENERIC
200
 
        ;;
201
 
  esac
202
 
}    
203
 
 
204
 
#
205
 
# validate_all_ve()
206
 
#
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).
209
 
#
210
 
# In case the output format should change, this function will need fixing.
211
 
#
212
 
validate_all_ve()
213
 
{
214
 
  declare -i retcode
215
 
 
216
 
  # VEID should be a valid VE
217
 
  `status_ve`
218
 
  retcode=$?
219
 
 
220
 
  if [[ $retcode != $OCF_SUCCESS && $retcode != $OCF_NOT_RUNNING ]]; then
221
 
    return $retcode
222
 
  fi
223
 
 
224
 
  return $OCF_SUCCESS
225
 
}
226
 
        
227
 
 
228
 
if [[ $# != 1 ]]; then
229
 
  usage
230
 
  exit $OCF_ERR_ARGS
231
 
fi
232
 
 
233
 
case "$1" in
234
 
  meta-data)
235
 
        meta_data
236
 
        exit $OCF_SUCCESS
237
 
        ;;
238
 
  usage) 
239
 
        usage
240
 
        exit $OCF_SUCCESS
241
 
        ;;
242
 
  *)
243
 
        ;;
244
 
esac
245
 
 
246
 
#
247
 
# check relevant environment variables for sanity and security
248
 
#
249
 
 
250
 
# empty string?
251
 
`test -z "$OCF_RESKEY_veid"`
252
 
 
253
 
declare -i veidtest1=$?
254
 
 
255
 
# really a number?
256
 
`echo "$OCF_RESKEY_veid" | egrep -q '^[[:digit:]]+$'`
257
 
 
258
 
if [[ $veidtest1 != 1 || $? != 0 ]]; then
259
 
  ocf_log err "OCF_RESKEY_veid not set or not a number."
260
 
  exit $OCF_ERR_ARGS
261
 
fi
262
 
 
263
 
declare -i VEID=$OCF_RESKEY_veid
264
 
 
265
 
#
266
 
# check that all relevant utilities are available
267
 
268
 
check_binary $VZCTL
269
 
check_binary $AWK
270
 
 
271
 
#
272
 
# finally... let's see what we are ordered to do :-)
273
 
#
274
 
case "$1" in
275
 
  start)
276
 
        start_ve
277
 
        ;;
278
 
  stop)
279
 
        stop_ve
280
 
        ;;
281
 
  status|monitor) 
282
 
        status_ve
283
 
        ;;
284
 
  validate-all)
285
 
        validate_all_ve
286
 
        ;;
287
 
  *)
288
 
        usage
289
 
        exit $OCF_ERR_UNIMPLEMENTED 
290
 
        ;;
291
 
esac
292
 
 
293
 
exit $?
294