summaryrefslogtreecommitdiff
blob: 7e3dc84ab805465ba6c9e26976e5fbc5849ef86d (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
#!/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.rc,v 1.6 2005/03/25 16:15:21 xmerlin Exp $

depend() {
	use net
	need ccs
	provide cluster-manager
}

umount_gfs_filesystems() {
	local sig retry
	local remaining="$(awk '$3 == "gfs" { 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" { 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
}


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
}

unload_gfs_modules() {
	if [ -f /proc/fs/gfs ]; then
		modules="gfs lock_harness"
	fi
	if [ -d /proc/cluster/lock_dlm ]; then
		modules="${modules} lock_dlm"
	fi
	if [ -d /proc/cluster/lock_gulm ]; then
		modules="${modules} lock_gulm"
	fi
	unload_modules ${modules}
}


start() {
	#if grep -qE "<[[:space:]]*gulm([[:space:]]|[>]|$)" /etc/cluster/cluster.conf
	#then
	#	die "<gulm> section detected in /etc/cluster/cluster.conf"
	#fi

	if [ ! -d /proc/cluster/config/cman ]; then
		load_modules cman
	fi

	ebegin "Starting cman"
	/sbin/cman_tool -t ${CMAN_CLUSTER_TIMEOUT} \
		-w join ${CMAN_JOIN_OPTS} > /dev/null
	
	if [ "$?" -ne 0 ]
	then
		ewend 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)"
			/sbin/cman_tool -t ${CMAN_QUORUM_TIMEOUT} -q wait
			eend $?
		fi
	fi
}

stop() {
	
	# umount GFS filesystems
	umount_gfs_filesystems
	
	# shutdown clvm, fenced services
	# need to be fixed (clvm missing)
	local fence_status="$(cman_tool services | awk '$1 ~ /Fence/ { print $3 }')"
	if [ -n "${fence_status}" ]; then
		if [ -x /sbin/fence_tool ]; then
			ebegin "Stopping fence domain"
			/sbin/fence_tool leave > /dev/null 2>&1
			eend $?
		fi
	fi
	
	# shutdown dlm, gfs
	unload_gfs_modules
	
	ebegin "Stopping cman"
	local retry stat
	local cman_status
	cman_status="$(cman_tool status | awk '$1 ~ /Membership/ { print $3 }')"
	
	if [ "${cman_status}" != "Not-in-Cluster" -a -d /proc/cluster/config/cman ]; then
		retry=3
		stat=1
		while [ "${stat}" -eq 1 -a "${retry}" -gt 0 ]
		do
			/sbin/cman_tool -w -t ${CMAN_SHUTDOWN_TIMEOUT} \
				leave ${CMAN_LEAVE_OPTS} > /dev/null
				
			stat=$?
			retry=$((${retry} -1))
		done
		
		#if [ "${stat}" -ne 0 ]; then
		#	/sbin/cman_tool -w -t 2 leave force > /dev/null
		#fi
		
		#if [ "$?" -ne 0 ]
		#then
		#	ewend 1 "Failed to stop cman"
		#else
		#	eend 0
		#fi
	else
		stat=0
	fi

	eend ${stat}

	if [ "${stat}" -eq 0 ]; then
		sleep 1s
		
		#ebegin "Unloading cman kernel module"
		#modprobe -r cman &> /dev/null || return 0
		#eend $?
		
		unload_modules cman
	fi
}