xref: /dflybsd-src/contrib/lvm2/dist/scripts/lvm2_monitoring_init_red_hat.in (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
186d7f5d3SJohn Marino#!/bin/bash
286d7f5d3SJohn Marino#
386d7f5d3SJohn Marino# Copyright (C) 2007-2009 Red Hat, Inc. All rights reserved.
486d7f5d3SJohn Marino#
586d7f5d3SJohn Marino# This copyrighted material is made available to anyone wishing to use,
686d7f5d3SJohn Marino# modify, copy, or redistribute it subject to the terms and conditions
786d7f5d3SJohn Marino# of the GNU General Public License v.2.
886d7f5d3SJohn Marino#
986d7f5d3SJohn Marino# You should have received a copy of the GNU General Public License
1086d7f5d3SJohn Marino# along with this program; if not, write to the Free Software Foundation,
1186d7f5d3SJohn Marino# Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
1286d7f5d3SJohn Marino#
1386d7f5d3SJohn Marino# This file is part of LVM2.
1486d7f5d3SJohn Marino# It is required for the proper handling of failures of LVM2 mirror
1586d7f5d3SJohn Marino# devices that were created using the -m option of lvcreate.
1686d7f5d3SJohn Marino#
1786d7f5d3SJohn Marino#
1886d7f5d3SJohn Marino# chkconfig: 12345 02 99
1986d7f5d3SJohn Marino# description: Starts and stops dmeventd monitoring for lvm2
2086d7f5d3SJohn Marino#
2186d7f5d3SJohn Marino# For Red-Hat-based distributions such as Fedora, RHEL, CentOS.
2286d7f5d3SJohn Marino#
2386d7f5d3SJohn Marino### BEGIN INIT INFO
2486d7f5d3SJohn Marino# Provides: lvm2-monitor
2586d7f5d3SJohn Marino# Required-Start: $local_fs
2686d7f5d3SJohn Marino# Required-Stop: $local_fs
2786d7f5d3SJohn Marino# Default-Start: 1 2 3 4 5
2886d7f5d3SJohn Marino# Default-Stop: 0 6
2986d7f5d3SJohn Marino# Short-Description: Monitoring of LVM2 mirrors, snapshots etc. using dmeventd
3086d7f5d3SJohn Marino### END INIT INFO
3186d7f5d3SJohn Marino
3286d7f5d3SJohn Marino. /etc/init.d/functions
3386d7f5d3SJohn Marino
3486d7f5d3SJohn MarinoDAEMON=lvm2_monitor
3586d7f5d3SJohn Marino
3686d7f5d3SJohn Marinoexec_prefix=@exec_prefix@
3786d7f5d3SJohn Marinosbindir=@sbindir@
3886d7f5d3SJohn Marino
3986d7f5d3SJohn MarinoVGCHANGE=${sbindir}/vgchange
4086d7f5d3SJohn MarinoVGS=${sbindir}/vgs
4186d7f5d3SJohn Marino
4286d7f5d3SJohn MarinoLOCK_FILE="/var/lock/subsys/$DAEMON"
4386d7f5d3SJohn Marino
4486d7f5d3SJohn MarinoWARN=1
4586d7f5d3SJohn Marino
4686d7f5d3SJohn Marinostart()
4786d7f5d3SJohn Marino{
4886d7f5d3SJohn Marino	ret=0
4986d7f5d3SJohn Marino	# TODO do we want to separate out already active groups only?
5086d7f5d3SJohn Marino	VGSLIST=`$VGS --noheadings -o name 2> /dev/null`
5186d7f5d3SJohn Marino	for vg in $VGSLIST
5286d7f5d3SJohn Marino	do
5386d7f5d3SJohn Marino	    action "Starting monitoring for VG $vg:" $VGCHANGE --monitor y $vg || ret=$?
5486d7f5d3SJohn Marino	done
5586d7f5d3SJohn Marino
5686d7f5d3SJohn Marino	return $ret
5786d7f5d3SJohn Marino}
5886d7f5d3SJohn Marino
5986d7f5d3SJohn Marino
6086d7f5d3SJohn Marinostop()
6186d7f5d3SJohn Marino{
6286d7f5d3SJohn Marino	ret=0
6386d7f5d3SJohn Marino	# TODO do we want to separate out already active groups only?
6486d7f5d3SJohn Marino	if test "$WARN" = "1"; then
6586d7f5d3SJohn Marino	   echo "Not stopping monitoring, this is a dangerous operation. Please use force-stop to override."
6686d7f5d3SJohn Marino	   return 1
6786d7f5d3SJohn Marino	fi
6886d7f5d3SJohn Marino	VGSLIST=`$VGS --noheadings -o name 2> /dev/null`
6986d7f5d3SJohn Marino	for vg in $VGSLIST
7086d7f5d3SJohn Marino	do
7186d7f5d3SJohn Marino	    action "Stopping monitoring for VG $vg:" $VGCHANGE --monitor n $vg || ret=$?
7286d7f5d3SJohn Marino	done
7386d7f5d3SJohn Marino	return $ret
7486d7f5d3SJohn Marino}
7586d7f5d3SJohn Marino
7686d7f5d3SJohn Marinortrn=1
7786d7f5d3SJohn Marino
7886d7f5d3SJohn Marino# See how we were called.
7986d7f5d3SJohn Marinocase "$1" in
8086d7f5d3SJohn Marino  start)
8186d7f5d3SJohn Marino	start
8286d7f5d3SJohn Marino	rtrn=$?
8386d7f5d3SJohn Marino	[ $rtrn = 0 ] && touch $LOCK_FILE
8486d7f5d3SJohn Marino	;;
8586d7f5d3SJohn Marino
8686d7f5d3SJohn Marino  force-stop)
8786d7f5d3SJohn Marino	WARN=0
8886d7f5d3SJohn Marino	stop
8986d7f5d3SJohn Marino	rtrn=$?
9086d7f5d3SJohn Marino	[ $rtrn = 0 ] && rm -f $LOCK_FILE
9186d7f5d3SJohn Marino	;;
9286d7f5d3SJohn Marino
9386d7f5d3SJohn Marino  stop)
9486d7f5d3SJohn Marino	test "$runlevel" = "0" && WARN=0
9586d7f5d3SJohn Marino	test "$runlevel" = "6" && WARN=0
9686d7f5d3SJohn Marino	stop
9786d7f5d3SJohn Marino	rtrn=$?
9886d7f5d3SJohn Marino	[ $rtrn = 0 ] && rm -f $LOCK_FILE
9986d7f5d3SJohn Marino	;;
10086d7f5d3SJohn Marino
10186d7f5d3SJohn Marino  restart)
10286d7f5d3SJohn Marino	WARN=0
10386d7f5d3SJohn Marino	if stop
10486d7f5d3SJohn Marino	then
10586d7f5d3SJohn Marino		start
10686d7f5d3SJohn Marino	fi
10786d7f5d3SJohn Marino	rtrn=$?
10886d7f5d3SJohn Marino	;;
10986d7f5d3SJohn Marino
11086d7f5d3SJohn Marino  status)
11186d7f5d3SJohn Marino	# TODO anyone with an idea how to dump monitored volumes?
11286d7f5d3SJohn Marino	;;
11386d7f5d3SJohn Marino
11486d7f5d3SJohn Marino  *)
11586d7f5d3SJohn Marino	echo $"Usage: $0 {start|stop|restart|status|force-stop}"
11686d7f5d3SJohn Marino	;;
11786d7f5d3SJohn Marinoesac
11886d7f5d3SJohn Marino
11986d7f5d3SJohn Marinoexit $rtrn
120