summaryrefslogtreecommitdiff
blob: 32abd47e48c25df1ae027e187bb55e772547d365 (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-2006 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/sys-fs/ocfs2-tools/files/Attic/ocfs2.init,v 1.2 2009/10/08 09:03:35 flameeyes dead $

depend() {
	need net localmount
	before netmount 
}

check_modules() {
	local MODULES="ocfs2_dlmfs ocfs2 ocfs2_dlm ocfs2_nodemanager configfs"
	local MODULE
	local MODPROBE="modprobe -l"
	local retval=0
	
	for MODULE in ${MODULES}; do
		if [ -z "`${MODPROBE} ${MODULE}`" ] ; then
			retval=1
		fi
	done
	if [ ${retval} -eq 1 ] ; then 
		ewarn "One or more required modules are not loaded."
                ewarn "Make sure you have "
                ewarn " - placed ocfs, dlmfs and configfs into /etc/modules.autoload.d/kernel-2.6"
                ewarn "For a (in)complete documentation, read /usr/share/doc/ocfs-<version>/INSTALL.GENTOO.gz"
	fi
	return ${retval}
}

check_pseudofs() { 
	local retval=0
	local HASMOUNT="mount -l -t"
	if [ -z "`${HASMOUNT} configfs`" ] ; then
		retval=1
	fi
	if [ -z "`${HASMOUNT} ocfs2_dlmfs`" ] ; then
		retval=1
	fi

	if [ ${retval} -eq 1 ]; then
		ewarn "One or more pseudo-filesystes are not mounted."
		ewarn "Make sure you have following lines in your /etc/fstab:"
		ewarn "none                    /config         configfs        defaults                0 0"
		ewarn "none                    /dlm            ocfs2_dlmfs     defaults                0 0"
		ewarn "For a (in)complete documentation, read /usr/share/doc/ocfs-<version>/INSTALL.GENTOO.gz"
	fi
	return ${retval}
}



start() {
	check_modules || return $? 
	check_pseudofs || return $?
	
	einfo "Starting OCFS2 cluster"
	for cluster in ${OCFS2_CLUSTER}; do
		ebegin " - ${cluster}"
		/sbin/o2cb_ctl -H -n ${cluster} -t cluster -a online=yes >/dev/null 2>&1
		eend $?
	done
}

stop() {
	# Shamelesly stolen from netmount
        local ret
        ebegin "Unmounting OCFS2 filesystems"
        [ -z "$(umount -art ocfs2 2>&1)" ]
        ret=$?
        eend ${ret} "Failed to simply unmount filesystems"
        [ ${ret} -eq 0 ] && return 0

        declare -a siglist=( "TERM" "KILL" "KILL" )
        local retry=0
        local remaining="go"

        while [ -n "${remaining}" -a ${retry} -lt 3 ]
        do
                remaining="$(awk '$3 ~ /'ocfs2'/ { if ($2 != "/") print $2 }' /proc/mounts | sort -r)"
                IFS=$'\n'
                set -- ${remaining//\\040/ }
                unset IFS
                [ -z "${remaining}" ] && break

                ebegin $'\t'"Unmounting ocfs2 filesystems (retry #$((retry+1)))"
                /bin/fuser -k -${siglist[$((retry++))]} -m "$@" &>/dev/null
                sleep 5
                umount "$@" &>/dev/null
                eend $? $'\t'"Failed to unmount filesystems"
        done

	
	einfo "Stopping OCFS2 cluster" 
	for cluster in ${OCFS_CLUSTERS}; do
		ebegin " - ${cluster}"
		/sbin/o2cb_ctl -H -n ${cluster} -t cluster -a online=no >/dev/null 2>&1
		eend $?
	done
}