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

« back to all changes in this revision

Viewing changes to resources/OCF/AoEtarget

  • 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/bash
2
 
#
3
 
#
4
 
# AoEtarget OCF RA. 
5
 
# Manages an ATA-over-Ethernet (AoE) target utilizing the vblade utility.
6
 
#
7
 
# Copyright (c) 2009 LINBIT HA-Solutions GmbH, Florian Haas
8
 
#                    All Rights Reserved.
9
 
#
10
 
# This program is free software; you can redistribute it and/or modify
11
 
# it under the terms of version 2 of the GNU General Public License as
12
 
# published by the Free Software Foundation.
13
 
#
14
 
# This program is distributed in the hope that it would be useful, but
15
 
# WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
 
#
18
 
# Further, this software is distributed without any warranty that it is
19
 
# free of the rightful claim of any third person regarding infringement
20
 
# or the like.  Any license provided herein, whether implied or
21
 
# otherwise, applies only to this software file.  Patent licenses, if
22
 
# any, provided herein do not apply to combinations of this program with
23
 
# other software, or any other product whatsoever.
24
 
#
25
 
# You should have received a copy of the GNU General Public License
26
 
# along with this program; if not, write the Free Software Foundation,
27
 
# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
28
 
#
29
 
 
30
 
######################################################################
31
 
# Initialization:
32
 
 
33
 
. ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs
34
 
LC_ALL="C"
35
 
LANG="C"
36
 
 
37
 
# Defaults
38
 
OCF_RESKEY_nic_default="eth0"
39
 
OCF_RESKEY_pid_default="${HA_RSCTMP}/AoEtarget-${OCF_RESOURCE_INSTANCE}.pid"
40
 
OCF_RESKEY_binary_default="/usr/sbin/vblade"
41
 
 
42
 
: ${OCF_RESKEY_nic=${OCF_RESKEY_nic_default}}
43
 
: ${OCF_RESKEY_pid=${OCF_RESKEY_pid_default}}
44
 
: ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}}
45
 
 
46
 
#######################################################################
47
 
 
48
 
meta_data() {
49
 
    cat <<EOF
50
 
<?xml version="1.0" encoding="UTF-8"?>
51
 
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
52
 
<resource-agent name="AoEtarget" version="0.1">
53
 
  <version>1.0</version>
54
 
  <longdesc lang="en">
55
 
This resource agent manages an ATA-over-Ethernet (AoE) target using vblade.
56
 
It exports any block device, or file, as an AoE target using the 
57
 
specified Ethernet device, shelf, and slot number.
58
 
</longdesc>
59
 
  <shortdesc lang="en">ATA-over-Ethernet (AoE) target agent</shortdesc>
60
 
  <parameters>
61
 
    <parameter name="device" required="1">
62
 
      <longdesc lang="en">
63
 
The local block device (or file) to export as an AoE target.
64
 
</longdesc>
65
 
      <shortdesc lang="en">Device to export</shortdesc>
66
 
      <content type="string"/>
67
 
    </parameter>
68
 
    <parameter name="nic" required="1">
69
 
      <longdesc lang="en">
70
 
The local Ethernet interface to use for exporting this AoE target.
71
 
</longdesc>
72
 
      <shortdesc lang="en">Ethernet interface</shortdesc>
73
 
      <content type="string" default="${OCF_RESKEY_nic_default}"/>
74
 
    </parameter>
75
 
    <parameter name="shelf" required="1">
76
 
      <longdesc lang="en">
77
 
The AoE shelf number to use when exporting this target.
78
 
</longdesc>
79
 
      <shortdesc lang="en">AoE shelf number</shortdesc>
80
 
      <content type="integer"/>
81
 
    </parameter>
82
 
    <parameter name="slot" required="1">
83
 
      <longdesc lang="en">
84
 
The AoE slot number to use when exporting this target.
85
 
</longdesc>
86
 
      <shortdesc lang="en">AoE slot number</shortdesc>
87
 
      <content type="integer"/>
88
 
    </parameter>
89
 
    <parameter name="pid" required="0" unique="1">
90
 
      <longdesc lang="en">
91
 
The file to record the daemon pid to.
92
 
</longdesc>
93
 
      <shortdesc lang="en">Daemon pid file</shortdesc>
94
 
      <content type="string" default="${OCF_RESKEY_pid_default}"/>
95
 
    </parameter>
96
 
    <parameter name="binary" required="0">
97
 
      <longdesc lang="en">
98
 
Location of the vblade binary.
99
 
</longdesc>
100
 
      <shortdesc lang="en">vblade binary</shortdesc>
101
 
      <content type="string" default="${OCF_RESKEY_binary_default}"/>
102
 
    </parameter>
103
 
  </parameters>
104
 
  <actions>
105
 
    <action name="start" timeout="15"/>
106
 
    <action name="stop" timeout="15"/>
107
 
    <action name="monitor" timeout="15" interval="10" depth="0" start-delay="0"/>
108
 
    <action name="reload" timeout="15"/>
109
 
    <action name="meta-data" timeout="5"/>
110
 
    <action name="validate-all" timeout="15"/>
111
 
  </actions>
112
 
</resource-agent>
113
 
EOF
114
 
}
115
 
 
116
 
#######################################################################
117
 
 
118
 
AoEtarget_usage() {
119
 
        cat <<END
120
 
usage: $0 {start|stop|status|monitor|validate-all|meta-data}
121
 
 
122
 
Expects to have a fully populated OCF RA-compliant environment set.
123
 
END
124
 
}
125
 
 
126
 
AoEtarget_start() {
127
 
    AoEtarget_monitor
128
 
    if [ $? =  $OCF_SUCCESS ]; then
129
 
        return $OCF_SUCCESS
130
 
    fi
131
 
    ocf_log info "Exporting device ${OCF_RESKEY_device} on ${OCF_RESKEY_nic} as shelf ${OCF_RESKEY_shelf}, slot ${OCF_RESKEY_slot}"
132
 
    ${OCF_RESKEY_binary} ${OCF_RESKEY_shelf} ${OCF_RESKEY_slot} \
133
 
        ${OCF_RESKEY_nic} ${OCF_RESKEY_device} 2>&1 &
134
 
    rc=$?
135
 
    pid=$!
136
 
    if [ $rc -ne 0 ]; then
137
 
        return $OCF_ERR_GENERIC
138
 
    fi
139
 
    echo $pid > ${OCF_RESKEY_pid} && return $OCF_SUCCESS
140
 
    return $OCF_ERR_GENERIC
141
 
}
142
 
 
143
 
AoEtarget_stop() {
144
 
    AoEtarget_monitor
145
 
    if [ $? -eq  $OCF_SUCCESS ]; then
146
 
        ocf_log info "Unxporting device ${OCF_RESKEY_device} on ${OCF_RESKEY_nic} as shelf ${OCF_RESKEY_shelf}, slot ${OCF_RESKEY_slot}"
147
 
        pid=$(cat ${OCF_RESKEY_pid})
148
 
        kill -TERM $pid
149
 
        # loop until we're really stopped, wait for the LRM to time us
150
 
        # out if not
151
 
        while AoEtarget_monitor; do
152
 
            sleep 1
153
 
        done
154
 
    fi
155
 
    # Clean up pid file
156
 
    rm -f ${OCF_RESKEY_pid}
157
 
    return $OCF_SUCCESS
158
 
}
159
 
 
160
 
AoEtarget_monitor() {
161
 
    ocf_pidfile_status ${OCF_RESKEY_pid} >/dev/null 2>&1
162
 
    rc=$?
163
 
    if [ $rc -eq 2 ]; then
164
 
        # no pid file, must assume we're not running
165
 
        return $OCF_NOT_RUNNING
166
 
    elif [ $rc -eq 1 ]; then
167
 
        # stale pid file, assume something went wrong
168
 
        return $OCF_ERR_GENERIC
169
 
    fi
170
 
    return $OCF_RUNNING
171
 
}
172
 
 
173
 
AoEtarget_validate() {
174
 
    # Is our binary executable?
175
 
    if [ ! -x ${OCF_RESKEY_binary} ]; then
176
 
        ocf_log error "${OCF_RESKEY_binary} not found or not executable"
177
 
        return $OCF_ERR_INSTALLED
178
 
    fi
179
 
 
180
 
    # Do we have all required variables?
181
 
    for var in device nic shelf slot pid; do
182
 
        param="OCF_RESKEY_${var}"
183
 
        if [ -z "${!param}" ]; then
184
 
            ocf_log error "Missing resource parameter \"$var\"!"
185
 
            return $OCF_ERR_CONFIGURED
186
 
        fi
187
 
    done
188
 
 
189
 
    # Is the pid file directory writable? 
190
 
    pid_dir=`dirname "$OCF_RESKEY_pid"`
191
 
    touch "$pid_dir/$$"
192
 
    if [ $? != 0 ]; then
193
 
        ocf_log error "Cannot create pid file in $pid_dir -- check directory permissions"
194
 
        return $OCF_ERR_INSTALLED
195
 
    fi
196
 
    rm "$pid_dir/$$"
197
 
 
198
 
    # Does the device we are trying to export exist?
199
 
    if [ ! -e ${OCF_RESKEY_device} ]; then
200
 
        ocf_log error "${OCF_RESKEY_device} does not exist"
201
 
        return $OCF_ERR_INSTALLED
202
 
    fi
203
 
    return $OCF_SUCCESS
204
 
}
205
 
 
206
 
case $1 in
207
 
  meta-data)
208
 
        meta_data
209
 
        exit $OCF_SUCCESS
210
 
        ;;
211
 
  usage|help)
212
 
        AoEtarget_usage
213
 
        exit $OCF_SUCCESS
214
 
        ;;
215
 
esac
216
 
 
217
 
# Everything except usage and meta-data must pass the validate test
218
 
AoEtarget_validate || exit $?
219
 
 
220
 
case $__OCF_ACTION in
221
 
    start)
222
 
        AoEtarget_start
223
 
        ;;
224
 
    stop)
225
 
        AoEtarget_stop
226
 
        ;;
227
 
    status|monitor)
228
 
        AoEtarget_monitor
229
 
        ;;
230
 
    reload)
231
 
        ocf_log err "Reloading..."
232
 
        AoEtarget_start
233
 
        ;;
234
 
    validate-all)
235
 
        AoEtarget_validate
236
 
        ;;
237
 
    *)
238
 
        AoEtarget_usage
239
 
        exit $OCF_ERR_UNIMPLEMENTED
240
 
        ;;
241
 
esac
242
 
 
243
 
rc=$?
244
 
ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
245
 
exit $rc
246