summaryrefslogtreecommitdiff
blob: 178e353462afa1428171860f01f7a8bca0676cc1 (plain)
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#!/sbin/runscript
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/sys-cluster/cman/files/cman-2.0x.rc,v 1.1 2008/03/17 23:39:07 xmerlin Exp $

CCSD_BIN="/usr/sbin/ccsd"

[ -z "$CCSD_OPTS" ] && CCSD_OPTS=""
[ -z "$CMAN_CLUSTER_TIMEOUT" ] && CMAN_CLUSTER_TIMEOUT=120
[ -z "$CMAN_QUORUM_TIMEOUT" ] && CMAN_QUORUM_TIMEOUT=0
[ -z "$CMAN_SHUTDOWN_TIMEOUT" ] && CMAN_SHUTDOWN_TIMEOUT=60
[ -z "$FENCED_START_TIMEOUT" ] && FENCED_START_TIMEOUT=300

depend() {
	use net
	after xend
	after xendomains
}

load_modules() {
        local module modules
        modules=$1

        for module in ${modules}; do
                ebegin "Loading ${module} kernel module"
                modprobe ${module} > /dev/null
                eend $? "Failed to load ${module} kernel module"
        done
}

unload_modules() {
        local module modules
        modules=$1

        for module in ${modules}; do
                ebegin "Unloading ${module} kernel module"
                modprobe -r ${module} > /dev/null
                eend $? "Failed to unload ${module} kernel module"
        done
}

check_configfs() {
        awk '{ print $2 }' /etc/mtab | grep "/sys/kernel/config" &> /dev/null\
                && awk '{ print $3 }' /etc/mtab | grep "configfs" &> /dev/null

        if [ $? -ne 0 ]; then
                ewarn "Please add the following line to /etc/fstab:"
                ewarn "none configfs /sys/kernel/config defaults 0 0"
                eend 1 "configfs not mounted at /sys/kernel/config"
        fi
}

mount_configfs()
{
	local module=$(awk '$2 == "configfs" { print $2 }' /proc/filesystems)

        if [ -z "${module}" ]; then
                load_modules "configfs"
                sleep 1s
        fi

	# configfs
	awk '{ print $2 }' /etc/mtab | grep "/sys/kernel/config" &> /dev/null \
		&& awk '{ print $3 }' /etc/mtab | grep "configfs" &> /dev/null

	if [ $? -ne 0 ]
	then
		ebegin "Mounting ConfigFS"
		/bin/mount -t configfs none /sys/kernel/config 2>&1
		eend $?
	fi
	return 0
}

umount_configfs() {
        local sig retry
        local entry entries

	entries="$(awk '$3 == "configfs" { print $2 }' /proc/mounts | sort -r)"

	for entry in $entries; do
		ebegin "Unmounting ConfigFS"
		umount $entry &>/dev/null
		eend $?
	done

        local module=$(awk '$1 == "configfs" { print $1 }' /proc/modules)

        if [ ! -z "${module}" ]; then
                unload_modules "configfs"
                sleep 1s
        fi
}

umount_gfs_filesystems() {
	local sig retry
	local remaining="$(awk '$3 == "gfs" || $3 == "gfs2" { print $2 }' /proc/mounts | sort -r)"

	if [ -n "${remaining}" ]
	then
	        sig=
	        retry=3
	        while [ -n "${remaining}" -a "${retry}" -gt 0 ]
	        do
	                if [ "${retry}" -lt 3 ]
			then
	                        ebegin "Unmounting GFS filesystems (retry)"
	                        umount ${remaining} &>/dev/null
	                        eend $? "Failed to unmount GFS filesystems this retry"
	                else
	                        ebegin "Unmounting GFS filesystems"
	                        umount ${remaining} &>/dev/null
	                        eend $? "Failed to unmount GFS filesystems"
	                fi
	                remaining="$(awk '$3 == "gfs" || $3 == "gfs2" { if ($2 != "/") print $2 }' /proc/mounts | sort -r)"
	                [ -z "${remaining}" ] && break
	                /bin/fuser -k -m ${sig} ${remaining} &>/dev/null
	                sleep 5
	                retry=$((${retry} -1))
	                sig=-9
	        done
	fi
}

unload_allmodules() {
	local modules

	modules=$(awk '$1 == "lock_gulm" || \
		$1 == "lock_dlm" || $1 == "dlm" || \
		$1 == "lock_harness" || $1 == "gfs2" || \
		$1 == "gfs" { print $1 }' /proc/modules)

	unload_modules "${modules}"
}

start_ccsd() {
        ebegin "Starting ccsd"
        start-stop-daemon --start --quiet \
                --exec ${CCSD_BIN} -- ${CCSD_OPTS}
        eend $?
}

stop_ccsd() {
	ebegin "Stopping ccsd"
	start-stop-daemon --stop --quiet \
		-s 9 --exec ${CCSD_BIN}
	eend $?
}

start_cman() {

	/usr/sbin/cman_tool status &> /dev/null
	if [ $? -ne 0 ]
	then
	        ebegin "Starting cman"
        	/usr/sbin/cman_tool -t ${CMAN_CLUSTER_TIMEOUT} \
                	-w join ${CMAN_JOIN_OPTS} > /dev/null

	        if [ "$?" -ne 0 ]
        	then
                	eend 1 "Failed to start cman"
	        else
        	        eend 0

                	# make sure that we are quorate?
	                if [ ${CMAN_QUORUM_TIMEOUT} -gt 0 ]
        	        then
                	        ebegin "Waiting for quorum (${CMAN_QUORUM_TIMEOUT} secs)"
                        	/usr/sbin/cman_tool -t ${CMAN_QUORUM_TIMEOUT} -q wait
	                        eend $?
        	        fi
	        fi
	else
		einfo "cman already running"
	fi
}

stop_cman() {
        ebegin "Stopping cman"
        local stat=0
        /usr/sbin/cman_tool status > /dev/null 2>&1
        if [ $? -eq 0 ]; then
                retry=3
                stat=1
                while [ "${stat}" -eq 1 -a "${retry}" -gt 0 ]
                do
                        /usr/sbin/cman_tool -w -t ${CMAN_SHUTDOWN_TIMEOUT} \
                                leave ${CMAN_LEAVE_OPTS} > /dev/null

                        stat=$?
                        retry=$((${retry} -1))
                done
        fi

        eend ${stat}
}

start_groupd() {
        ebegin "Starting groupd"
	start-stop-daemon --start --exec /usr/sbin/groupd --name groupd
        eend $?
}

stop_groupd() {
	ebegin "Stopping groupd"
	start-stop-daemon --stop --exec /usr/sbin/groupd --name groupd
	eend $?
}

start_fenced() {
        ebegin "Starting fenced"
        start-stop-daemon --start --exec /usr/sbin/fenced --name fenced
        eend $?

        ebegin "Joining fence domain"
        /usr/sbin/fence_tool join ${FENCED_OPTS}> /dev/null 2>&1
        eend $?
}

stop_fenced() {
        # fenced services
        local fence_status="$(cman_tool services | awk '$1 ~ /fence/ { print $3 }')"
        if [ -n "${fence_status}" ]; then
                if [ -x /usr/sbin/fence_tool ]; then
                        ebegin "Leaving fence domain"
                        /usr/sbin/fence_tool leave > /dev/null 2>&1
                        eend $?
                fi
        fi

	ebegin "Stopping fenced"
	start-stop-daemon --stop --exec /usr/sbin/fenced --name fenced
	eend $?
}

start_gfs_controld() {
        ebegin "Starting gfs_controld"
        start-stop-daemon --start --exec /usr/sbin/gfs_controld --name gfs_controld
        eend $?
}

stop_gfs_controld() {
        ebegin "Stopping gfs_controld"
        start-stop-daemon --stop --exec /usr/sbin/gfs_controld --name gfs_controld
        eend $?
}

start_dlm_controld() {
        ebegin "Starting dlm_controld"
        start-stop-daemon --start --exec /usr/sbin/dlm_controld --name dlm_controld
        eend $?
}

stop_dlm_controld() {
        ebegin "Stopping dlm_controld"
        start-stop-daemon --stop --exec /usr/sbin/dlm_controld --name dlm_controld
        eend $?
}

start() {
	load_modules "dlm lock_dlm"

	mount_configfs
	start_ccsd
	start_cman
	start_groupd
	start_fenced
	start_dlm_controld
	start_gfs_controld	
}

stop() {
	# umount GFS filesystems
	umount_gfs_filesystems

	stop_fenced
	stop_cman

	stop_gfs_controld
	stop_dlm_controld
	stop_groupd

	stop_ccsd
	umount_configfs	
        unload_allmodules
}