1#!/bin/bash
2#
3# Copyright (C) 2007 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### BEGIN INIT INFO
22# Provides:
23### END INIT INFO
24
25. /etc/init.d/functions
26
27VGCHANGE="/usr/sbin/vgchange"
28WARN=1
29
30start()
31{
32          ret=0
33          # TODO do we want to separate out already active groups only?
34          VGS=`vgs --noheadings -o name 2> /dev/null`
35          for vg in $VGS
36          do
37              action "Starting monitoring for VG $vg:" $VGCHANGE --monitor y $vg || ret=$?
38          done
39
40          return $ret
41}
42
43
44stop()
45{
46          ret=0
47          # TODO do we want to separate out already active groups only?
48          if test "$WARN" = "1"; then
49             echo "Not stopping monitoring, this is a dangerous operation. Please use force-stop to override."
50             return 1
51          fi
52          VGS=`vgs --noheadings -o name 2> /dev/null`
53          for vg in $VGS
54          do
55              action "Stopping monitoring for VG $vg:" $VGCHANGE --monitor n $vg || ret=$?
56          done
57          return $ret
58}
59
60result=1
61
62# See how we were called.
63case "$1" in
64  start)
65          start
66          result=$?
67          ;;
68
69  force-stop)
70          WARN=0
71          stop
72          result=$?
73          ;;
74
75  stop)
76          test "$runlevel" = "0" && WARN=0
77          test "$runlevel" = "6" && WARN=0
78          stop
79          result=$?
80          ;;
81
82  restart)
83          WARN=0
84          if stop
85          then
86                    start
87          fi
88          result=$?
89          ;;
90
91  status)
92          # TODO anyone with an idea how to dump monitored volumes?
93          ;;
94
95  *)
96          echo $"Usage: $0 {start|stop|restart|status|force-stop}"
97          ;;
98esac
99
100exit $result
101