2009-09-17 03:22:40 +04:00
#!/bin/bash
#
# Copyright (C) 2007-2009 Red Hat, Inc. All rights reserved.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions
# of the GNU General Public License v.2.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
2016-01-21 13:49:46 +03:00
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2009-09-17 03:22:40 +04:00
#
# This file is part of LVM2.
# It is required for the proper handling of failures of LVM2 mirror
# devices that were created using the -m option of lvcreate.
#
#
# chkconfig: 12345 02 99
# description: Starts and stops dmeventd monitoring for lvm2
#
# For Red-Hat-based distributions such as Fedora, RHEL, CentOS.
#
### BEGIN INIT INFO
2009-09-17 03:40:19 +04:00
# Provides: lvm2-monitor
2009-09-17 03:22:40 +04:00
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Default-Start: 1 2 3 4 5
# Default-Stop: 0 6
2010-01-05 23:56:51 +03:00
# Short-Description: Monitoring of LVM2 mirrors, snapshots etc. using dmeventd or progress polling
2009-09-17 03:22:40 +04:00
### END INIT INFO
. /etc/init.d/functions
2010-04-15 23:15:03 +04:00
DAEMON=lvm2-monitor
2015-02-27 17:38:34 +03:00
DMEVENTD_DAEMON=dmeventd
2009-09-17 03:22:40 +04:00
2017-10-25 18:08:00 +03:00
sbindir=@SBINDIR@
2009-09-17 03:22:40 +04:00
2017-10-25 18:08:00 +03:00
VGCHANGE="$sbindir/vgchange"
VGS="$sbindir/vgs"
LVS="$sbindir/lvs"
2009-09-17 03:22:40 +04:00
2017-10-25 18:08:00 +03:00
LOCK_FILE="@DEFAULT_SYS_LOCK_DIR@/subsys/$DAEMON"
2015-02-27 17:48:10 +03:00
PID_FILE="@DMEVENTD_PIDFILE@"
2009-09-17 03:22:40 +04:00
WARN=1
2011-08-11 19:27:46 +04:00
export LVM_SUPPRESS_LOCKING_FAILURE_MESSAGES=1
2009-09-17 03:22:40 +04:00
2015-02-27 17:38:34 +03:00
rh_status() {
2017-10-25 18:02:31 +03:00
status -p "$PID_FILE" "$DMEVENTD_DAEMON"
2015-02-27 17:38:34 +03:00
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
2009-09-17 03:22:40 +04:00
start()
{
ret=0
# TODO do we want to separate out already active groups only?
2014-02-17 19:25:32 +04:00
VGSLIST=`$VGS --noheadings -o name --ignoreskippedcluster --config 'log{command_names=0 prefix=" "}' 2> /dev/null`
2009-09-17 03:22:40 +04:00
for vg in $VGSLIST
do
2017-10-25 18:02:31 +03:00
action "Starting monitoring for VG $vg:" "$VGCHANGE" --monitor y --poll y --ignoreskippedcluster --config 'log{command_names=0 prefix=" "}' $vg || ret=$?
2009-09-17 03:22:40 +04:00
done
return $ret
}
stop()
{
ret=0
# TODO do we want to separate out already active groups only?
if test "$WARN" = "1"; then
echo "Not stopping monitoring, this is a dangerous operation. Please use force-stop to override."
return 1
fi
2014-02-17 19:25:32 +04:00
VGSLIST=`$VGS --noheadings -o name --ignoreskippedcluster --config 'log{command_names=0 prefix=" "}' 2> /dev/null`
2009-09-17 03:22:40 +04:00
for vg in $VGSLIST
do
2017-10-25 18:02:31 +03:00
action "Stopping monitoring for VG $vg:" "$VGCHANGE" --monitor n --ignoreskippedcluster --config 'log{command_names=0 prefix=" "}' $vg || ret=$?
2009-09-17 03:22:40 +04:00
done
return $ret
}
rtrn=1
# See how we were called.
case "$1" in
start)
2015-02-27 17:38:34 +03:00
rh_status_q && exit 0
2009-09-17 03:22:40 +04:00
start
rtrn=$?
2017-10-25 18:02:31 +03:00
[ "$rtrn" = 0 ] && touch "$LOCK_FILE"
2009-09-17 03:22:40 +04:00
;;
force-stop)
2015-02-27 17:38:34 +03:00
rh_status_q || exit 0
2009-09-17 03:22:40 +04:00
WARN=0
stop
rtrn=$?
2017-10-25 18:02:31 +03:00
[ "$rtrn" = 0 ] && rm -f "$LOCK_FILE"
2009-09-17 03:22:40 +04:00
;;
stop)
2015-02-27 17:38:34 +03:00
rh_status_q || exit 0
2009-09-17 03:22:40 +04:00
test "$runlevel" = "0" && WARN=0
test "$runlevel" = "6" && WARN=0
stop
rtrn=$?
2017-10-25 18:02:31 +03:00
[ "$rtrn" = 0 ] && rm -f "$LOCK_FILE"
2009-09-17 03:22:40 +04:00
;;
restart)
WARN=0
if stop
then
start
fi
rtrn=$?
;;
status)
2015-02-27 17:38:34 +03:00
rh_status
rtrn=$?
2017-10-25 18:02:31 +03:00
[ "$rtrn" = 0 ] && "$LVS" -S 'seg_monitor=monitored' -o lv_full_name,seg_monitor
2009-09-17 03:22:40 +04:00
;;
*)
echo $"Usage: $0 {start|stop|restart|status|force-stop}"
;;
esac
exit $rtrn