summaryrefslogtreecommitdiff
blob: ee52247e4b9ef70b99a641bff196e6fc04bac29b (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
#!/sbin/runscript
# Copyright 1999-2008 Gentoo Foundation
# Distributed under the terms of the GNU General Public License, v2 or later
# $Header: /var/cvsroot/gentoo-x86/sys-fs/gfs2/files/gfs2.rc,v 1.1 2008/11/13 19:19:30 xmerlin Exp $

opts="${opts} mountall"

depend() {
	local myneed="cman"
	local devices="$(awk '!/^#/ && $3 == "gfs2" && $4 !~ /noauto/ {print $1 }' /etc/fstab)"

	if [ -n "${devices}" ]; then
		local device=""
		for device in ${devices}; do
			if [ -n "$(echo "${device}" | awk '$1 ~ /\/dev\/gnbd/')" ]; then
				myneed="${myneed} gnbd-client"
			else
				if [ -n "$(echo "${device}" | awk '$1 ~ /\/dev\/vg/')" ]; then
					myneed="${myneed} clvmd"
				fi
			fi
		done
	fi

	use dns logger net
	need ${myneed}
}

mount_gfs2_filesystems() {
	local remaining=""
	remaining="$(awk '!/^#/ && $3 == "gfs2"  { if ($4 !~ "noauto") print $1 }' /etc/fstab)"
	
	if [ -n "${remaining}" ]; then
	
		local device=""
		local remaining_verified=""
		
		for device in ${remaining}; do
			if [ -b ${device} ]; then
				remaining_verified="${remaining_verified} ${device}"
			else
				ewarn "Block device ${device} not found!!"
			fi
		done
		
		if [ -n "${remaining_verified}" ]; then
			einfo "Mounting GFS filesystems"
			device=""
			for device in ${remaining_verified}; do
				local target="$(awk '!/^#/ && $3 == "gfs2" && $1 == device { print $2 }' device=${device} /etc/fstab)"
				local mounted="$(awk '$3 == "gfs2" && $1 == device { print $2 }' device=${device} /proc/mounts)"
				local options="$(awk '!/^#/ && $3 == "gfs2" && $1 == device { print $4 }' device=${device} /etc/fstab)"
				
				# mount only filesystems not already mounted
				if [ -z "${mounted}" ]; then
					ebegin "--> mounting ${device} on ${target}"
					mount -t gfs2 ${device} ${target} -o ${options} >/dev/null
					eend $?
				else
					einfo "--> ${device} already mounted on ${target}"
					eend 0
				fi
			done
		else
			einfo "No GFS filesystems to automount"
		fi
	fi
}


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

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
}

load_gfs2_modules() {
	if [ ! -f /proc/fs/gfs2 ]; then
		load_modules gfs2
	fi
}

unload_gfs2_modules() {
	if [ -f /proc/fs/gfs2 ]; then
		unload_modules gfs2
	fi
}

mountall() {
	mount_gfs2_filesystems
}

start() {
	einfo "Starting gfs2 cluster:"
	
	if [ ! -f /etc/ntp.conf ] ; then
		eerror "Please create /etc/ntp.conf"
		eerror "Sample conf: /usr/share/ntp/ntp.conf"
		eend 1
	fi
	
	load_gfs2_modules
	mount_gfs2_filesystems
}

stop() {
	einfo "Stopping gfs2 cluster:"
	
	umount_gfs2_filesystems
	unload_gfs2_modules
}