summaryrefslogtreecommitdiff
blob: 0fac0a61b514b0eef34809ece23b3fd8ada5fde0 (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
# /lib/rcscripts/addons/lvm2-stop.sh
# $Header: /var/cvsroot/gentoo-x86/sys-fs/lvm2/files/lvm2-stop.sh,v 1.4 2005/06/18 07:11:05 rocket Exp $

# Stop LVM2
if [ -x /sbin/vgchange ] && \
   [ -x /sbin/lvdisplay ] && \
   [ -x /sbin/vgdisplay ] && \
   [ -x /sbin/lvchange ] && \
   [ -f /etc/lvmtab -o -d /etc/lvm ] && \
   [ -d /proc/lvm  -o "`grep device-mapper /proc/misc 2>/dev/null`" ]
then
	einfo "Shutting down the Logical Volume Manager"
	# If these commands fail it is not currently an issue
	# as the system is going down anyway based on the current LVM 
	# functionality as described in this forum thread
	#https://www.redhat.com/archives/linux-lvm/2001-May/msg00523.html

	LOGICAL_VOLUMES=`lvdisplay |grep "LV Name"|sed -e 's/.*LV Name\s*\(.*\)/\1/'|sort`
	VOLUME_GROUPS=`vgdisplay |grep "VG Name"|sed -e 's/.*VG Name\s*\(.*\)/\1/'|sort`
	for x in ${LOGICAL_VOLUMES}
	do
		LV_IS_ACTIVE=`lvdisplay ${x}|grep "# open"|awk '{print $3}'`
		if [ "${LV_IS_ACTIVE}" = 0 ]
		then
			ebegin "  Shutting Down logical volume: ${x} "
			lvchange -an --ignorelockingfailure -P ${x} >/dev/null
			eend $?
		fi
	done

	for x in ${VOLUME_GROUPS}
	do
		VG_HAS_ACTIVE_LV=`vgdisplay ${x}|grep "Open LV"|sed -e 's/.*Open LV\s*\(.*\)/\1/'`
		if [ "${VG_HAS_ACTIVE_LV}" = 0 ]
		then
			ebegin "  Shutting Down volume group: ${x} "
			vgchange -an --ignorelockingfailure -P ${x} >/dev/null
			eend
		fi
	done

	for x in ${LOGICAL_VOLUMES}
	do
		LV_IS_ACTIVE=`lvdisplay ${x}|grep "# open"|sed -e 's/.*# open\s*\(.*\)/\1/'`
		if [ "${LV_IS_ACTIVE}" = 1 ]
		then
			
			ROOT_DEVICE=`mount|grep " / "|awk '{print $1}'`
			if [ ! ${ROOT_DEVICE} = ${x} ]
			then
				ewarn "  Unable to shutdown: ${x} "
			fi
		fi
	done
	einfo "Finished Shutting down the Logical Volume Manager"
fi

# vim:ts=4