5
# Description: Manages a glusterd server as a (typically cloned)
8
# Authors: Florian Haas (hastexo Professional Services GmbH)
9
# Jiri Lunacek (Hosting90 Systems s.r.o.)
11
# License: GNU General Public License (GPL)
13
#######################################################################
16
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
17
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
19
# Convenience variables
20
# When sysconfdir and localstatedir aren't passed in as
21
# configure flags, they're defined in terms of prefix
23
SHORTHOSTNAME=`hostname -s`
24
#######################################################################
26
OCF_RESKEY_binary_default="gluster"
28
: ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}}
33
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
34
<resource-agent name="volume" version="0.1">
35
<version>0.1</version>
37
Manages a GlusterFS volume and monitors its bricks. When a resource of
38
this type is configured as a clone (as is commonly the case), then it
39
must have clone ordering enabled.
41
<shortdesc lang="en">Manages a GlusterFS volume</shortdesc>
43
<parameter name="volname" required="1">
45
The name of the volume to manage.
47
<shortdesc lang="en">volume name</shortdesc>
48
<content type="string"/>
50
<parameter name="binary">
52
Name of the gluster executable. Specify a full absolute
53
path if the binary is not in your \$PATH.
55
<shortdesc lang="en">gluster executable</shortdesc>
56
<content type="string" default="$OCF_RESKEY_binary_default"/>
58
<parameter name="peer_map">
60
Mapping of hostname - peer name in the gluster cluster
61
in format hostname1:peername1,hostname2:peername2,...
63
<shortdesc lang="en">gluster peer map</shortdesc>
64
<content type="string" default=""/>
68
<action name="start" timeout="20" />
69
<action name="stop" timeout="20" />
70
<action name="monitor" timeout="20" interval="10" />
71
<action name="reload" timeout="20" />
72
<action name="meta-data" timeout="5" />
73
<action name="validate-all" timeout="20" />
80
if [ -n "${OCF_RESKEY_peer_map}" ]; then
81
SHORTHOSTNAME=`echo "${OCF_RESKEY_peer_map}" | egrep -o "$SHORTHOSTNAME\:[^,]+" | awk -F: '{print $2}'`
86
voldir="@GLUSTERD_WORKDIR@/vols/${OCF_RESKEY_volname}"
88
[ -d ${voldir} ] || return 1
96
volpid_dir="/var/run/gluster/vols/${OCF_RESKEY_volname}"
98
[ -d ${volpid_dir} ] || return 1
107
voldir=`volume_getdir`
108
infofile="${voldir}/info"
110
[ -e ${infofile} ] || return 1
112
echo "`sed -n -e "s/^brick-.\+=${SHORTHOSTNAME}://p" < ${infofile}`"
122
volpid_dir=`volume_getpid_dir`
123
bricks=`volume_getbricks`
125
if [ -z "$bricks" ]; then
129
for brick in ${bricks}; do
130
pidfile="${volpid_dir}/${SHORTHOSTNAME}${brick}.pid"
131
[ -e $pidfile ] || return 1
141
# exit immediately if configuration is not valid
142
volume_validate_all || exit $?
144
# if resource is already running, bail out early
145
if volume_monitor; then
146
ocf_log info "Resource is already running"
150
# actually start up the resource here
151
ocf_run "$OCF_RESKEY_binary" \
152
volume start "$OCF_RESKEY_volname" force || exit $OCF_ERR_GENERIC
154
# After the resource has been started, check whether it started up
155
# correctly. If the resource starts asynchronously, the agent may
156
# spin on the monitor function here -- if the resource does not
157
# start up within the defined timeout, the cluster manager will
158
# consider the start action failed
159
while ! volume_monitor; do
160
ocf_log debug "Resource has not started yet, waiting"
164
# only return $OCF_SUCCESS if _everything_ succeeded as expected
172
# exit immediately if configuration is not valid
173
volume_validate_all || exit $?
179
# Currently running. Normal, expected behavior.
180
ocf_log debug "Resource is currently running"
183
# Currently not running. Nothing to do.
184
ocf_log info "Resource is already stopped"
189
# actually shut down the resource here (make sure to immediately
190
# exit with an $OCF_ERR_ error code if anything goes seriously
192
pids=`volume_getpids`
194
ocf_run kill -s TERM $pid
197
# After the resource has been stopped, check whether it shut down
198
# correctly. If the resource stops asynchronously, the agent may
199
# spin on the monitor function here -- if the resource does not
200
# shut down within the defined timeout, the cluster manager will
201
# consider the stop action failed
202
while volume_monitor; do
203
ocf_log debug "Resource has not stopped yet, waiting"
207
# only return $OCF_SUCCESS if _everything_ succeeded as expected
215
pids=`volume_getpids` || return $OCF_NOT_RUNNING
218
ocf_run kill -s 0 $pid || return $OCF_NOT_RUNNING
221
ocf_log debug "Local bricks for volume ${OCF_RESKEY_volname} running with PIDs $pids"
225
volume_validate_all() {
226
# Test for configuration errors first
227
if [ -z "${OCF_RESKEY_volname}" ]; then
228
ocf_log err 'Missing required parameter "volname"'
229
return $OCF_ERR_CONFIGURED
232
# Test for required binaries
233
check_binary $OCF_RESKEY_binary
235
if [ -z "$SHORTHOSTNAME" ]; then
236
ocf_log err 'Unable to get host in node map'
237
return $OCF_ERR_CONFIGURED
245
# Make sure meta-data and usage always succeed
247
meta-data) volume_meta_data
250
usage|help) volume_usage
255
# Anything other than meta-data and usage must pass validation
256
volume_validate_all || exit $?
258
# Translate each action into the appropriate function call
262
status|monitor) volume_monitor;;
263
reload) ocf_log info "Reloading..."
267
notify) exit $OCF_SUCCESS;;
269
exit $OCF_ERR_UNIMPLEMENTED
274
# The resource agent may optionally log a debug message
275
ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION returned $rc"