glusterfs

Форк
0
/
volume.in 
276 строк · 7.3 Кб
1
#!/bin/sh
2
#
3
# glusterd
4
#
5
# Description:  Manages a glusterd server as a (typically cloned)
6
#               HA resource
7
#
8
# Authors:      Florian Haas (hastexo Professional Services GmbH)
9
#               Jiri Lunacek (Hosting90 Systems s.r.o.)
10
#
11
# License:      GNU General Public License (GPL)
12

13
#######################################################################
14
# Initialization:
15

16
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
17
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
18

19
# Convenience variables
20
# When sysconfdir and localstatedir aren't passed in as
21
# configure flags, they're defined in terms of prefix
22
prefix=@prefix@
23
SHORTHOSTNAME=`hostname -s`
24
#######################################################################
25

26
OCF_RESKEY_binary_default="gluster"
27

28
: ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}}
29

30
volume_meta_data() {
31
    cat <<EOF
32
<?xml version="1.0"?>
33
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
34
<resource-agent name="volume" version="0.1">
35
  <version>0.1</version>
36
  <longdesc lang="en">
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.
40
  </longdesc>
41
  <shortdesc lang="en">Manages a GlusterFS volume</shortdesc>
42
  <parameters>
43
    <parameter name="volname" required="1">
44
      <longdesc lang="en">
45
      The name of the volume to manage.
46
      </longdesc>
47
      <shortdesc lang="en">volume name</shortdesc>
48
      <content type="string"/>
49
    </parameter>
50
    <parameter name="binary">
51
      <longdesc lang="en">
52
      Name of the gluster executable. Specify a full absolute
53
      path if the binary is not in your \$PATH.
54
      </longdesc>
55
      <shortdesc lang="en">gluster executable</shortdesc>
56
      <content type="string" default="$OCF_RESKEY_binary_default"/>
57
    </parameter>
58
    <parameter name="peer_map">
59
      <longdesc lang="en">
60
      Mapping of hostname - peer name in the gluster cluster
61
      in format hostname1:peername1,hostname2:peername2,...
62
      </longdesc>
63
      <shortdesc lang="en">gluster peer map</shortdesc>
64
      <content type="string" default=""/>
65
    </parameter>
66
  </parameters>
67
  <actions>
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" />
74
  </actions>
75
</resource-agent>
76
EOF
77

78
}
79

80
if [ -n "${OCF_RESKEY_peer_map}" ]; then
81
    SHORTHOSTNAME=`echo "${OCF_RESKEY_peer_map}" | egrep -o "$SHORTHOSTNAME\:[^,]+" | awk -F: '{print $2}'`
82
fi
83

84
volume_getdir() {
85
    local voldir
86
    voldir="@GLUSTERD_WORKDIR@/vols/${OCF_RESKEY_volname}"
87

88
    [ -d ${voldir} ] || return 1
89

90
    echo "${voldir}"
91
    return 0
92
}
93

94
volume_getpid_dir() {
95
    local volpid_dir
96
    volpid_dir="/var/run/gluster/vols/${OCF_RESKEY_volname}"
97

98
    [ -d ${volpid_dir} ] || return 1
99

100
    echo "${volpid_dir}"
101
    return 0
102
}
103

104
volume_getbricks() {
105
    local infofile
106
    local voldir
107
    voldir=`volume_getdir`
108
    infofile="${voldir}/info"
109

110
    [ -e ${infofile} ] || return 1
111

112
    echo "`sed -n -e "s/^brick-.\+=${SHORTHOSTNAME}://p" < ${infofile}`"
113
    return 0
114
}
115

116
volume_getpids() {
117
    local bricks
118
    local pidfile
119
    local infofile
120
    local volpid_dir
121

122
    volpid_dir=`volume_getpid_dir`
123
    bricks=`volume_getbricks`
124
    
125
    if [ -z "$bricks" ]; then
126
        return 1
127
    fi
128

129
    for brick in ${bricks}; do
130
	pidfile="${volpid_dir}/${SHORTHOSTNAME}${brick}.pid"
131
	[ -e $pidfile ] || return 1
132
	cat $pidfile
133
    done
134

135
    return 0
136
}
137

138
volume_start() {
139
    local volume_options
140

141
    # exit immediately if configuration is not valid
142
    volume_validate_all || exit $?
143

144
    # if resource is already running, bail out early
145
    if volume_monitor; then
146
        ocf_log info "Resource is already running"
147
        return $OCF_SUCCESS
148
    fi
149

150
    # actually start up the resource here
151
    ocf_run "$OCF_RESKEY_binary" \
152
	volume start "$OCF_RESKEY_volname" force || exit $OCF_ERR_GENERIC
153

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"
161
        sleep 1
162
    done
163

164
    # only return $OCF_SUCCESS if _everything_ succeeded as expected
165
    return $OCF_SUCCESS
166
}
167

168
volume_stop() {
169
    local rc
170
    local pid
171

172
    # exit immediately if configuration is not valid
173
    volume_validate_all || exit $?
174

175
    volume_monitor
176
    rc=$?
177
    case "$rc" in
178
        "$OCF_SUCCESS")
179
            # Currently running. Normal, expected behavior.
180
            ocf_log debug "Resource is currently running"
181
            ;;
182
        "$OCF_NOT_RUNNING")
183
            # Currently not running. Nothing to do.
184
            ocf_log info "Resource is already stopped"
185
            return $OCF_SUCCESS
186
            ;;
187
    esac
188

189
    # actually shut down the resource here (make sure to immediately
190
    # exit with an $OCF_ERR_ error code if anything goes seriously
191
    # wrong)
192
    pids=`volume_getpids`
193
    for pid in $pids; do
194
	ocf_run kill -s TERM $pid
195
    done
196

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"
204
        sleep 1
205
    done
206

207
    # only return $OCF_SUCCESS if _everything_ succeeded as expected
208
    return $OCF_SUCCESS
209

210
}
211

212
volume_monitor() {
213
    local pid
214

215
    pids=`volume_getpids` || return $OCF_NOT_RUNNING
216

217
    for pid in $pids; do
218
	ocf_run kill -s 0 $pid || return $OCF_NOT_RUNNING
219
    done
220

221
    ocf_log debug "Local bricks for volume ${OCF_RESKEY_volname} running with PIDs $pids"
222
    return $OCF_SUCCESS
223
}
224

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
230
    fi
231

232
    # Test for required binaries
233
    check_binary $OCF_RESKEY_binary
234
	
235
	if [ -z "$SHORTHOSTNAME" ]; then
236
		ocf_log err 'Unable to get host in node map'
237
		return $OCF_ERR_CONFIGURED
238
	fi
239

240
    return $OCF_SUCCESS
241
}
242

243

244

245
# Make sure meta-data and usage always succeed
246
case $__OCF_ACTION in
247
meta-data)      volume_meta_data
248
                exit $OCF_SUCCESS
249
                ;;
250
usage|help)     volume_usage
251
                exit $OCF_SUCCESS
252
                ;;
253
esac
254

255
# Anything other than meta-data and usage must pass validation
256
volume_validate_all || exit $?
257

258
# Translate each action into the appropriate function call
259
case $__OCF_ACTION in
260
start)          volume_start;;
261
stop)           volume_stop;;
262
status|monitor) volume_monitor;;
263
reload)         ocf_log info "Reloading..."
264
                volume_start
265
                ;;
266
validate-all)   ;;
267
notify)		exit $OCF_SUCCESS;;
268
*)              volume_usage
269
                exit $OCF_ERR_UNIMPLEMENTED
270
                ;;
271
esac
272
rc=$?
273

274
# The resource agent may optionally log a debug message
275
ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION returned $rc"
276
exit $rc
277

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.