File: rapiddisk.sh.pacemaker

package info (click to toggle)
rapiddisk 9.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 952 kB
  • sloc: ansic: 6,760; sh: 1,364; makefile: 325; python: 105
file content (208 lines) | stat: -rwxr-xr-x 4,175 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/bin/bash
#
# Copyright (C) 2015 - 2025 Petros Koutoupis. All rights reserved.
#

PATH=/bin:/sbin:/usr/bin:/usr/sbin

export PATH

: ${OCF_FUNCTIONS_DIR=/usr/lib/ocf/lib/heartbeat}
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs


RDSK_bin="/sbin/rapiddisk"

#######################################################################

metadata()
{
        cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="rapiddisk.sh" version="1.1">
<version>1.1</version>

<longdesc lang="en">
This defines a standard RapidDisk HA failover.
</longdesc>

<shortdesc lang="en">
Defines a standard RapidDisk HA failover.
</shortdesc>

<parameters>
<parameter name="name" unique="1" required="1">
<longdesc lang="en">
This is the name of the resource rule.
</longdesc>
<shortdesc lang="en">Name</shortdesc>
<content type="string"/>
</parameter>

<parameter name="volume" unique="1" required="1">
<longdesc lang="en">
This is the absolute path of the storage device to map with RapidDisk-Cache.
</longdesc>
<shortdesc lang="en">Path of storage device for RapidDisk-Cache.</shortdesc>
<content type="string"/>
</parameter>

<parameter name="size" unique="1" required="1">
<longdesc lang="en">
This is the size of the RapidDisk (and cache for RapidDisk-Cache) volume.
</longdesc>
<shortdesc lang="en">
RapidDisk size.
</shortdesc>
<content type="string"/>
</parameter>

<parameter name="mode" unique="1" required="0">
<longdesc lang="en">
This caching mode: Write-Through (wt) or Write-Around (wa).
</longdesc>
<shortdesc lang="en">
Caching mode: wt or wa.
</shortdesc>
<content type="string"/>
</parameter>
</parameters>

<actions>
<action name="start" timeout="300"/>
<action name="stop" timeout="30"/>
<action name="status" depth="10" timeout="20" interval="30"/>
<action name="monitor" depth="10" timeout="20" interval="30"/>
<action name="meta-data" timeout="5"/>
<action name="validate-all" timeout="5"/>
</actions>
</resource-agent>
END

        exit $OCF_SUCCESS
}


verify_all()
{
	if [ -z "$OCF_RESKEY_name" ]; then
		ocf_log err "Invalid Name Of Service: $OCF_RESKEY_name"
		return $OCF_ERR_ARGS
	fi

	if [ -z "$OCF_RESKEY_volume" ]; then
		ocf_log err "Invalid Name Of Volume: $OCF_RESKEY_volume"
		return $OCF_ERR_ARGS
	fi

        if [ -z "$OCF_RESKEY_size" ]; then
		ocf_log err "Invalid Size Of RapidDisk Volume: $OCF_RESKEY_size"
                return $OCF_ERR_ARGS
        fi

	return $OCF_SUCCESS
}


do_start()
{
	verify_all || exit $?

	if do_status; then
		ocf_log info "Starting Service $OCF_RESOURCE_INSTANCE > Already running"
		return $OCF_SUCCESS
	fi

        if [ -z "$OCF_RESKEY_mode" ]; then
                mode="wt"
        else
                mode=$OCF_RESKEY_mode
        fi

	output=`$RDSK_bin --attach $OCF_RESKEY_size`
	if [ $? -ne 0 ]; then
		ocf_log info "Unable to create a RapidDisk volume of $OCF_RESKEY_size MB"
		return $OCF_ERR_GENERIC
	fi
	volume="$OCF_RESKEY_volume"
	rdsk=`echo $output|sed -e 's/^.*rd/rd/' -e 's/ .*$//'`
	$RDSK_bin --cache-map $rdsk $volume $mode

        return $OCF_SUCCESS
}


do_stop()
{
	verify_all || exit $?

	if [ -z "$OCF_RESKEY_mode" ]; then
		mode="wt"
	else
		mode=$OCF_RESKEY_mode
	fi

	cache="rc-${mode}_`echo $OCF_RESKEY_volume|rev|cut -d'/' -f1|rev`"
	output=`$RDSK_bin --short-list|grep "$cache:"`
	$RDSK_bin --cache-unmap $cache
	$RDSK_bin --detach `echo "$output"|sed -e 's/^rc.*://' -e 's/,.*$//'`

        return $OCF_SUCCESS
}


do_status()
{
	verify_all || exit $?

	if [ -z "$OCF_RESKEY_mode" ]; then
		mode="wt"
	else
		mode=$OCF_RESKEY_mode
	fi

	volume=`echo $OCF_RESKEY_volume|rev|cut -d'/' -f1|rev`
	if [ -e "/dev/mapper/rc-${mode}_$volume" ]; then
		return $OCF_SUCCESS
	fi
	ocf_log debug "RapidDisk resource for $OCF_RESKEY_volume is not running."
	return $OCF_NOT_RUNNING
}


#
#
#

case $1 in
	validate-all|verify-all)
		verify_all
		exit $?
		;;
	start)
		do_start
		exit $?
		;;
	stop)
		do_stop
		exit $?
		;;
	restart)
		do_stop
		do_start
		exit $?
		;;
	status|monitor)
		do_status
		exit $?
		;;
	meta-data)
		metadata
		exit 0
		;;
	*)
		echo "usage: $0 {start|stop|restart|status|meta-data|validate-all}"
		exit $OCF_ERR_UNIMPLEMENTED
		;;
esac