~ubuntu-branches/debian/stretch/resource-agents/stretch

« back to all changes in this revision

Viewing changes to heartbeat/sfex

  • Committer: Bazaar Package Importer
  • Author(s): Andres Rodriguez
  • Date: 2011-06-10 16:26:35 UTC
  • Revision ID: james.westby@ubuntu.com-20110610162635-yiy0vfopqw4trzgx
Tags: upstream-3.9.0
ImportĀ upstreamĀ versionĀ 3.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
#
 
3
#       Shared Disk File EXclusiveness (SF-EX) OCF RA. 
 
4
#       prevent a destruction of data on shared disk file system 
 
5
#       due to Split-Brain.
 
6
#
 
7
# This program is free software; you can redistribute it and/or
 
8
# modify it under the terms of the GNU General Public License
 
9
# as published by the Free Software Foundation; either version 2
 
10
# of the License, or (at your option) any later version.
 
11
 
12
# This program is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
# GNU General Public License for more details.
 
16
 
17
# You should have received a copy of the GNU General Public License
 
18
# along with this program; if not, write to the Free Software
 
19
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
 
20
# 02110-1301, USA.
 
21
#
 
22
# Copyright (c) 2007 NIPPON TELEGRAPH AND TELEPHONE CORPORATION
 
23
#
 
24
# NOTE:
 
25
#       As a prerequisite for running SF-EX, one device should be
 
26
#       initialized as below.
 
27
#
 
28
#               sfex_init [-n <numlocks>] <device>
 
29
#
 
30
#       Example:
 
31
#
 
32
#               /usr/sbin/sfex_init -n 10 /dev/sdb1
 
33
#
 
34
#       if further information is necessary, See README.
 
35
#
 
36
#######################################################################
 
37
# Initialization:
 
38
 
 
39
# switching ocf-shellfuncs path
 
40
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
 
41
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
 
42
 
 
43
#######################################################################
 
44
 
 
45
SFEX_DAEMON=${HA_BIN}/sfex_daemon
 
46
 
 
47
usage() {
 
48
    cat <<END
 
49
    usage: $0 {start|stop|monitor|meta-data}
 
50
END
 
51
}
 
52
 
 
53
meta_data() {
 
54
    cat <<END
 
55
<?xml version="1.0"?>
 
56
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
 
57
<resource-agent name="sfex">
 
58
<version>1.3</version>
 
59
 
 
60
<longdesc lang="en">
 
61
Resource script for SF-EX. It manages a shared storage medium exclusively .
 
62
</longdesc>
 
63
<shortdesc lang="en">Manages exclusive access to shared storage using Shared Disk File EXclusiveness (SF-EX)</shortdesc>
 
64
<parameters>
 
65
<parameter name="device" unique="0" required="1">
 
66
<longdesc lang="en">
 
67
Block device path that stores exclusive control data.
 
68
</longdesc>
 
69
<shortdesc lang="en">block device</shortdesc>
 
70
<content type="string" default="" />
 
71
</parameter>
 
72
<parameter name="index" unique="0" required="0">
 
73
<longdesc lang="en">
 
74
Location in block device where exclusive control data is stored. 1 or more is specified. Default is 1.
 
75
</longdesc>
 
76
<shortdesc lang="en">index</shortdesc>
 
77
<content type="integer" default="1" />
 
78
</parameter>
 
79
<parameter name="collision_timeout" unique="0" required="0">
 
80
<longdesc lang="en">
 
81
Waiting time when a collision of lock acquisition is detected. Default is 1 second.
 
82
</longdesc>
 
83
<shortdesc lang="en">waiting time for lock acquisition</shortdesc>
 
84
<content type="integer" default="1" />
 
85
</parameter>
 
86
<parameter name="monitor_interval" unique="0" required="0">
 
87
<longdesc lang="en">
 
88
Monitor interval(sec). Default is 10 seconds
 
89
</longdesc>
 
90
<shortdesc lang="en">monitor interval</shortdesc>
 
91
<content type="integer" default="10" />
 
92
</parameter>
 
93
<parameter name="lock_timeout" unique="0" required="0">
 
94
<longdesc lang="en">
 
95
Valid term of lock(sec). Default is 100 seconds.
 
96
The lock_timeout is calculated by the following formula.
 
97
 
 
98
  lock_timeout = monitor_interval + "The expiration time of the lock"
 
99
 
 
100
We suggest 90 seconds as a default value of the "The expiration time of the lock", but you should change it in consideration of access delay to the shared disk and the switch time of the multipath driver.
 
101
 
 
102
The lock timeout have an impact on start action timeout because start action timeout value is calculated by the following formula.
 
103
 
 
104
  start timeout = collision_timeout + lock_timeout + "safety margin"
 
105
 
 
106
The "safety margin" is decided within the range of about 10-20 seconds(It depends on your system requirement).
 
107
</longdesc>
 
108
<shortdesc lang="en">Valid term of lock</shortdesc>
 
109
<content type="integer" default="100" />
 
110
</parameter>
 
111
</parameters>
 
112
 
 
113
<actions>
 
114
<action name="start" timeout="120s" />
 
115
<action name="stop" timeout="20s" />
 
116
<action name="monitor" depth="0" timeout="10s" interval="10s" />
 
117
<action name="meta-data" timeout="5s" />
 
118
<action name="validate-all" timeout="5s" />
 
119
</actions>
 
120
</resource-agent>
 
121
END
 
122
}
 
123
 
 
124
#
 
125
# START: Exclusive control starts.
 
126
#
 
127
# It loops permanently until the lock can be acquired when locked with 
 
128
# the other node. In this case, the reception of the stop signal by the 
 
129
# timeout time passage set to CIB becomes the only stop opportunity. 
 
130
#
 
131
sfex_start() {
 
132
        ocf_log info "sfex_daemon: starting..."
 
133
 
 
134
        sfex_monitor
 
135
        if [ $? -eq $OCF_SUCCESS ]; then
 
136
                ocf_log info "sfex_daemon already started."
 
137
                return $OCF_SUCCESS
 
138
        fi
 
139
 
 
140
        $SFEX_DAEMON -i $INDEX -c $COLLISION_TIMEOUT -t $LOCK_TIMEOUT -m $MONITOR_INTERVAL -r ${OCF_RESOURCE_INSTANCE} $DEVICE
 
141
 
 
142
        rc=$?
 
143
        if [ $rc -ne 0 ]; then
 
144
                ocf_log err "sfex_daemon failed to start."
 
145
                return $OCF_ERR_GENERIC
 
146
        fi
 
147
        
 
148
        while :
 
149
        do
 
150
                sfex_monitor
 
151
                if [ $? -eq $OCF_SUCCESS ]; then
 
152
                        ocf_log info "sfex_daemon: started."
 
153
                        return $OCF_SUCCESS
 
154
                fi
 
155
                ocf_log debug "Waiting for the start-up of the sfex_daemon..."
 
156
                sleep 1
 
157
        done
 
158
        ocf_log err "Can't find a sfex_daemon process. Starting a sfex_daemon failed."
 
159
        return $OCF_ERR_GENERIC
 
160
}
 
161
 
 
162
#
 
163
# STOP: stop exclusive control 
 
164
#
 
165
sfex_stop() {
 
166
        ocf_log info "sfex_daemon: stopping..."
 
167
 
 
168
        # Check the sfex daemon has already stopped.
 
169
        sfex_monitor
 
170
        if [ $? -eq $OCF_NOT_RUNNING ]; then
 
171
                ocf_log info "sfex_daemon already stopped."
 
172
                return $OCF_SUCCESS
 
173
        fi
 
174
 
 
175
        # Stop sfex daemon by sending SIGTERM signal.
 
176
        pid=`/usr/bin/pgrep -f "$SFEX_DAEMON .* ${OCF_RESOURCE_INSTANCE} "`
 
177
        /bin/kill $pid
 
178
        rc=$?
 
179
        if [ $rc -ne 0 ]; then
 
180
                ocf_log err "sfex_daemon failed to stop"
 
181
                return $rc
 
182
        fi
 
183
 
 
184
#sfex could be in state D if the device is gone, and then not terminate.        
 
185
#Wait and check again if the daemon is already properly shutdown.
 
186
 
 
187
        shutdown_timeout=$((($OCF_RESKEY_CRM_meta_timeout/1000)-5))
 
188
        count=0
 
189
        while [ $count -lt $shutdown_timeout ]
 
190
        do
 
191
                sfex_monitor
 
192
                if [ $? -eq $OCF_NOT_RUNNING ]; then
 
193
                        ocf_log info "sfex_daemon: stopped."
 
194
                        return $OCF_SUCCESS
 
195
                fi
 
196
                count=`expr $count + 1`
 
197
                ocf_log debug "waiting for sfex_daemon to exit ($count/$shutdown_timeout)"
 
198
                sleep 1
 
199
        done
 
200
        
 
201
        sfex_monitor
 
202
        if [ $? -ne $OCF_NOT_RUNNING ]; then
 
203
                ocf_log warn "regular shutdown of sfex_daemon timed out, using SIGKILL"
 
204
                /bin/kill -s KILL $pid
 
205
        fi
 
206
 
 
207
        while :
 
208
        do
 
209
                sfex_monitor
 
210
                if [ $? -eq $OCF_NOT_RUNNING ]; then
 
211
                        break;
 
212
                fi
 
213
                ocf_log debug "waiting for sfex_daemon to exit after SIGKILL"
 
214
                sleep 1
 
215
        done
 
216
 
 
217
        ocf_log info "sfex_daemon: stopped."
 
218
        return $OCF_SUCCESS
 
219
}
 
220
 
 
221
sfex_monitor() {
 
222
        ocf_log debug "sfex_monitor: started..."
 
223
 
 
224
        # Find a sfex_daemon process using daemon name and resource name.
 
225
        if /usr/bin/pgrep -f "$SFEX_DAEMON .* ${OCF_RESOURCE_INSTANCE} " > /dev/null 2>&1; then
 
226
                ocf_log debug "sfex_monitor: complete. sfex_daemon is running."
 
227
                return $OCF_SUCCESS
 
228
        fi
 
229
 
 
230
        ocf_log debug "sfex_monitor: complete. sfex_daemon is not running."
 
231
        return $OCF_NOT_RUNNING
 
232
}
 
233
 
 
234
#
 
235
# main process 
 
236
#
 
237
 
 
238
# check arguments
 
239
if [ $# -ne 1 ]; then
 
240
        usage
 
241
        exit $OCF_ERR_ARGS
 
242
fi
 
243
OP=$1
 
244
 
 
245
# These operations do not require instance parameters
 
246
case $OP in
 
247
        meta-data)
 
248
                meta_data
 
249
                exit $OCF_SUCCESS
 
250
                ;;
 
251
        usage)
 
252
                usage
 
253
                exit $OCF_SUCCESS
 
254
                ;;
 
255
esac
 
256
 
 
257
# check parameters
 
258
DEVICE=$OCF_RESKEY_device
 
259
INDEX=${OCF_RESKEY_index:-1}
 
260
COLLISION_TIMEOUT=${OCF_RESKEY_collision_timeout:-1}
 
261
LOCK_TIMEOUT=${OCF_RESKEY_lock_timeout:-100}
 
262
MONITOR_INTERVAL=${OCF_RESKEY_monitor_interval:-10}
 
263
 
 
264
sfex_validate () {
 
265
if [ -z "$DEVICE" ]; then
 
266
        ocf_log err "Please set OCF_RESKEY_device to device for sfex meta-data"
 
267
        exit $OCF_ERR_ARGS
 
268
fi
 
269
if [ ! -w "$DEVICE" ]; then
 
270
        ocf_log warn "Couldn't find device [$DEVICE]. Expected /dev/??? to exist"
 
271
        exit $OCF_ERR_ARGS
 
272
fi
 
273
}
 
274
 
 
275
if [ -n "$OCF_RESKEY_CRM_meta_clone" ]; then
 
276
        ocf_log err "THIS RA DO NOT SUPPORT CLONE MODE!"
 
277
        exit $OCF_ERR_CONFIGURED
 
278
fi
 
279
 
 
280
case $OP in
 
281
        start)
 
282
                sfex_start
 
283
                ;;
 
284
        stop)
 
285
                sfex_stop
 
286
                ;;
 
287
        monitor)
 
288
                sfex_monitor
 
289
                ;;
 
290
        validate-all)
 
291
                sfex_validate
 
292
                ;;
 
293
        *)
 
294
                exit $OCF_ERR_UNIMPLEMENTED
 
295
                ;;
 
296
esac
 
297
exit $?