summaryrefslogtreecommitdiff
blob: 12ae6cb637c5e01e8ef749b82e5ac44595d407f0 (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
#!/sbin/runscript
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License, v2 or later
# $Header: /var/cvsroot/gentoo-x86/sys-cluster/gnbd/files/gnbd-client.rc,v 1.2 2005/03/23 14:09:48 xmerlin Exp $

depend() {
	use dns logger
	need net
	need fenced
}

start() {
	if [ ! -f /etc/gnbdtab ] ; then
		eerror "Please create /etc/gnbdtab"
		eerror "Sample conf: /etc/gnbdtab"
		return 1
	fi

	ebegin "Loading needed kernel modules for gnbd"
	modprobe gnbd
	eend $? "Failed to load needed kernel modules for gnbd"
	
	GNBD=`cat /etc/gnbdtab | egrep '^import'`
	if [ -n "$GNBD" ] ; then
		ebegin "Importing all GNBDs devices"
		einfo "$(awk '/^import/ { print "--> server:", $2 }' /etc/gnbdtab )"
		cat /etc/gnbdtab | awk '/^import/ { print "-i", $2 }' | xargs gnbd_import  > /dev/null
		eend $? "Failed to import gnbd devices"
	fi
}

stop() {

	local sig retry
	local remaining="$(awk '$3 ~ /gfs/ && $1 ~ /\/dev\/gnbd\// { if ($2 != "/") print $2 }' /proc/mounts | sort -r)"

	if [ -z "${remaining}" ]
	then
		ebegin "Unmounting GFS filesystems (GNBDs imported devices)"
		eend 0
	else
	        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/ && $1 ~ /\/dev\/gnbd\// { 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



	local GNBD_MONITOR_PROC

	ebegin "Unimporting all GNBDs devices"
	gnbd_import -q -R &> /dev/null
	eend $?

	GNBD_MONITOR_PROC="$(pgrep gnbd_clusterd)"
	if [ -n "${GNBD_MONITOR_PROC}" ]; then
		ebegin "Stopping gnbd_monitor"
		killall gnbd_monitor &> /dev/null
		eend $?
	fi

	ebegin "Unloading gnbd kernel module"
	modprobe -r gnbd
	eend $? "Failed to unload gnbd kernel module"	
}