1#!/bin/bash 2# 3# Copyright (C) 2007-2009 Red Hat, Inc. All rights reserved. 4# 5# This copyrighted material is made available to anyone wishing to use, 6# modify, copy, or redistribute it subject to the terms and conditions 7# of the GNU General Public License v.2. 8# 9# You should have received a copy of the GNU General Public License 10# along with this program; if not, write to the Free Software Foundation, 11# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 12# 13# This file is part of LVM2. 14# It is required for the proper handling of failures of LVM2 mirror 15# devices that were created using the -m option of lvcreate. 16# 17# 18# chkconfig: 12345 02 99 19# description: Starts and stops dmeventd monitoring for lvm2 20# 21# For Red-Hat-based distributions such as Fedora, RHEL, CentOS. 22# 23### BEGIN INIT INFO 24# Provides: lvm2-monitor 25# Required-Start: $local_fs 26# Required-Stop: $local_fs 27# Default-Start: 1 2 3 4 5 28# Default-Stop: 0 6 29# Short-Description: Monitoring of LVM2 mirrors, snapshots etc. using dmeventd 30### END INIT INFO 31 32. /etc/init.d/functions 33 34DAEMON=lvm2_monitor 35 36exec_prefix=@exec_prefix@ 37sbindir=@sbindir@ 38 39VGCHANGE=${sbindir}/vgchange 40VGS=${sbindir}/vgs 41 42LOCK_FILE="/var/lock/subsys/$DAEMON" 43 44WARN=1 45 46start() 47{ 48 ret=0 49 # TODO do we want to separate out already active groups only? 50 VGSLIST=`$VGS --noheadings -o name 2> /dev/null` 51 for vg in $VGSLIST 52 do 53 action "Starting monitoring for VG $vg:" $VGCHANGE --monitor y $vg || ret=$? 54 done 55 56 return $ret 57} 58 59 60stop() 61{ 62 ret=0 63 # TODO do we want to separate out already active groups only? 64 if test "$WARN" = "1"; then 65 echo "Not stopping monitoring, this is a dangerous operation. Please use force-stop to override." 66 return 1 67 fi 68 VGSLIST=`$VGS --noheadings -o name 2> /dev/null` 69 for vg in $VGSLIST 70 do 71 action "Stopping monitoring for VG $vg:" $VGCHANGE --monitor n $vg || ret=$? 72 done 73 return $ret 74} 75 76rtrn=1 77 78# See how we were called. 79case "$1" in 80 start) 81 start 82 rtrn=$? 83 [ $rtrn = 0 ] && touch $LOCK_FILE 84 ;; 85 86 force-stop) 87 WARN=0 88 stop 89 rtrn=$? 90 [ $rtrn = 0 ] && rm -f $LOCK_FILE 91 ;; 92 93 stop) 94 test "$runlevel" = "0" && WARN=0 95 test "$runlevel" = "6" && WARN=0 96 stop 97 rtrn=$? 98 [ $rtrn = 0 ] && rm -f $LOCK_FILE 99 ;; 100 101 restart) 102 WARN=0 103 if stop 104 then 105 start 106 fi 107 rtrn=$? 108 ;; 109 110 status) 111 # TODO anyone with an idea how to dump monitored volumes? 112 ;; 113 114 *) 115 echo $"Usage: $0 {start|stop|restart|status|force-stop}" 116 ;; 117esac 118 119exit $rtrn 120