summaryrefslogtreecommitdiff
blob: fbe8eb2d1d10e83fbcaab19f2eee80ce0738cd85 (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
#!/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-2.0x.rc,v 1.1 2008/03/17 16:59:57 xmerlin Exp $

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

load_modules() {
	local module modules
	modules=$1
	
	for module in ${modules}; do
		ebegin "Loading ${module} kernel module"
		modprobe ${module}
		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}
		eend $? "Failed to unload ${module} kernel module"
	done
}


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

	load_modules 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 -l gnbd_import ${GNBD_CLIENT_OPTS} > /dev/null
		eend $? "Failed to import gnbd devices"
	fi
}

stop() {
	# umount manually mounted gfs filesystems
	local sig retry
	local remaining="$(awk '( $3 == "gfs" || $3 == "gfs2" ) && $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" || $3 == "gfs2" ) && $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
	
	unload_modules gnbd
}