2008-11-19 23:14:24 +03:00
#!/bin/bash
#
2010-02-26 16:07:43 +03:00
# clvmd - Clustered LVM Daemon init script
#
2008-11-19 23:14:24 +03:00
# chkconfig: - 24 76
2010-02-26 16:07:43 +03:00
# description: Cluster daemon for userland logical volume management tools.
2013-06-07 16:07:56 +04:00
# pidfile: @CLVMD_PIDFILE@
2008-11-19 23:14:24 +03:00
#
# For Red-Hat-based distributions such as Fedora, RHEL, CentOS.
2010-02-26 16:07:43 +03:00
#
2008-11-19 23:14:24 +03:00
### BEGIN INIT INFO
2010-02-26 16:07:43 +03:00
# Provides: clvmd
2010-08-23 15:37:02 +04:00
# Required-Start: $local_fs@CLVMD_CMANAGERS@
# Required-Stop: $local_fs@CLVMD_CMANAGERS@
2010-02-26 16:07:43 +03:00
# Short-Description: This service is Clusterd LVM Daemon.
# Description: Cluster daemon for userland logical volume management tools.
2008-11-19 23:14:24 +03:00
### END INIT INFO
2010-02-26 16:07:43 +03:00
. /etc/rc.d/init.d/functions
2008-11-19 23:14:24 +03:00
DAEMON=clvmd
2017-10-25 18:08:00 +03:00
sbindir="@SBINDIR@"
usrsbindir="@USRSBINDIR@"
2008-11-19 23:14:24 +03:00
2017-10-25 18:02:31 +03:00
lvm_vgchange="$sbindir/vgchange"
lvm_vgs="$sbindir/vgs"
lvm_vgscan="$sbindir/vgscan"
lvm_lvs="$sbindir/lvs"
2008-11-19 23:14:24 +03:00
2010-02-26 16:07:43 +03:00
CLVMDOPTS="-T30"
2008-11-19 23:14:24 +03:00
[ -f /etc/sysconfig/cluster ] && . /etc/sysconfig/cluster
2017-10-25 18:02:31 +03:00
[ -f "/etc/sysconfig/$DAEMON" ] && . "/etc/sysconfig/$DAEMON"
2008-11-19 23:14:24 +03:00
2009-02-10 14:53:33 +03:00
[ -n "$CLVMD_CLUSTER_IFACE" ] && CLVMDOPTS="$CLVMDOPTS -I $CLVMD_CLUSTER_IFACE"
2010-02-26 16:07:43 +03:00
# allow up to $CLVMD_STOP_TIMEOUT seconds to clvmd to complete exit operations
# default to 10 seconds
2014-11-25 17:18:58 +03:00
[ -z $CLVMD_STOP_TIMEOUT ] && CLVMD_STOP_TIMEOUT=10
2010-02-26 16:07:43 +03:00
2008-11-19 23:14:24 +03:00
LOCK_FILE="/var/lock/subsys/$DAEMON"
2010-02-26 16:07:43 +03:00
clustered_vgs() {
2017-10-25 18:02:31 +03:00
"$lvm_vgs" --noheadings -o vg_name -S 'vg_clustered=1' 2>/dev/null
2010-02-26 16:07:43 +03:00
}
2010-06-23 20:24:13 +04:00
clustered_active_lvs() {
2017-10-25 18:02:31 +03:00
"$lvm_lvs" --noheadings -o lv_name -S 'vg_clustered=1 && lv_active!=""' 2>/dev/null
2010-02-26 16:07:43 +03:00
}
2008-11-19 23:14:24 +03:00
2010-02-26 16:07:43 +03:00
rh_status() {
2017-10-25 18:02:31 +03:00
status "$DAEMON"
2008-11-19 23:14:24 +03:00
}
2010-02-26 16:07:43 +03:00
rh_status_q() {
rh_status >/dev/null 2>&1
}
start()
2008-11-19 23:14:24 +03:00
{
2010-02-26 16:07:43 +03:00
if ! rh_status_q; then
echo -n "Starting $DAEMON: "
2017-10-25 18:08:00 +03:00
"$usrsbindir/$DAEMON" $CLVMDOPTS || return $?
2008-11-19 23:14:24 +03:00
echo
2010-02-26 16:07:43 +03:00
fi
# Refresh local cache.
#
# It's possible that new PVs were added to this, or other VGs
# while this node was down. So we run vgscan here to avoid
# any potential "Missing UUID" messages with subsequent
# LVM commands.
# The following step would be better and more informative to the user:
# 'action "Refreshing VG(s) local cache:" ${lvm_vgscan}'
# but it could show warnings such as:
# 'clvmd not running on node x-y-z Unable to obtain global lock.'
# and the action would be shown as FAILED when in reality it didn't.
# Ideally vgscan should have a startup mode that would not print
# unnecessary warnings.
2017-10-25 18:02:31 +03:00
"$lvm_vgscan" > /dev/null 2>&1
2010-02-26 16:07:43 +03:00
2017-10-25 18:02:31 +03:00
action "Activating VG(s):" "$lvm_vgchange" -aay $LVM_VGS || return $?
2010-02-26 16:07:43 +03:00
2017-10-25 18:02:31 +03:00
touch "$LOCK_FILE"
2010-02-26 16:07:43 +03:00
return 0
2008-11-19 23:14:24 +03:00
}
wait_for_finish()
{
count=0
2010-02-26 16:07:43 +03:00
while [ "$count" -le "$CLVMD_STOP_TIMEOUT" ] && \
rh_status_q ]; do
2008-11-19 23:14:24 +03:00
sleep 1
2010-02-26 16:07:43 +03:00
count=$((count+1))
2008-11-19 23:14:24 +03:00
done
2010-02-26 16:07:43 +03:00
! rh_status_q
}
stop()
{
rh_status_q || return 0
2010-05-17 07:18:27 +04:00
[ -z "$LVM_VGS" ] && LVM_VGS="$(clustered_vgs)"
if [ -n "$LVM_VGS" ]; then
2017-10-25 18:02:31 +03:00
action "Deactivating clustered VG(s):" "$lvm_vgchange" -anl $LVM_VGS || return $?
2010-05-17 07:18:27 +04:00
fi
2010-02-26 16:07:43 +03:00
2017-10-25 18:02:31 +03:00
action "Signaling $DAEMON to exit" kill -TERM "$(pidofproc "$DAEMON")" || return $?
2010-02-26 16:07:43 +03:00
# wait half second before we start the waiting loop or we will show
# the loop more time than really necessary
usleep 500000
# clvmd could take some time to stop
rh_status_q && action "Waiting for $DAEMON to exit:" wait_for_finish
if rh_status_q; then
echo -n "$DAEMON failed to exit"
failure
echo
2008-11-19 23:14:24 +03:00
return 1
else
2010-02-26 16:07:43 +03:00
echo -n "$DAEMON terminated"
success
echo
2008-11-19 23:14:24 +03:00
fi
2017-10-25 18:02:31 +03:00
rm -f "$LOCK_FILE"
2009-05-29 22:34:10 +04:00
2010-02-26 16:07:43 +03:00
return 0
2009-05-29 22:34:10 +04:00
}
2010-02-26 16:07:43 +03:00
reload() {
rh_status_q || exit 7
2017-10-25 18:08:00 +03:00
action "Reloading $DAEMON configuration: " "$usrsbindir/$DAEMON" -R || return $?
2009-05-29 22:34:10 +04:00
}
2010-02-26 16:07:43 +03:00
restart() {
# if stop fails, restart will return the error and not attempt
# another start. Even if start is protected by rh_status_q,
# that would avoid spawning another daemon, it would try to
# reactivate the VGs.
2010-04-20 18:07:37 +04:00
# Try to get clvmd to restart itself. This will preserve
# exclusive LV locks
2017-10-25 18:08:00 +03:00
action "Restarting $DAEMON: " "$usrsbindir/$DAEMON" -S
2010-04-20 18:07:37 +04:00
# If that fails then do a normal stop & restart
if [ $? != 0 ]; then
stop && start
2010-06-04 01:03:53 +04:00
return $?
2010-04-20 18:07:37 +04:00
else
2017-10-25 18:02:31 +03:00
touch "$LOCK_FILE"
2010-06-04 01:03:53 +04:00
return 0
2010-04-20 18:07:37 +04:00
fi
2010-02-26 16:07:43 +03:00
}
2008-11-19 23:14:24 +03:00
2010-08-12 13:14:59 +04:00
[ "$EUID" != "0" ] && {
echo "clvmd init script can only be executed as root user"
exit 4
}
2008-11-19 23:14:24 +03:00
# See how we were called.
case "$1" in
start)
start
rtrn=$?
;;
stop)
stop
rtrn=$?
;;
2010-02-26 16:07:43 +03:00
restart|force-reload)
restart
2008-11-19 23:14:24 +03:00
rtrn=$?
;;
2010-02-26 16:07:43 +03:00
condrestart|try-restart)
rh_status_q || exit 0
restart
rtrn=$?
;;
2009-05-29 22:34:10 +04:00
reload)
reload
2010-02-26 16:07:43 +03:00
rtrn=$?
2009-05-29 22:34:10 +04:00
;;
2008-11-19 23:14:24 +03:00
status)
2009-05-29 22:34:10 +04:00
rh_status
2008-11-19 23:14:24 +03:00
rtrn=$?
2017-10-25 18:02:31 +03:00
if [ "$rtrn" = 0 ]; then
2010-02-26 16:07:43 +03:00
cvgs="$(clustered_vgs)"
2010-06-23 20:24:13 +04:00
echo Clustered Volume Groups: ${cvgs:-"(none)"}
clvs="$(clustered_active_lvs)"
2010-02-26 16:07:43 +03:00
echo Active clustered Logical Volumes: ${clvs:-"(none)"}
fi
2008-11-19 23:14:24 +03:00
;;
*)
2010-02-26 16:07:43 +03:00
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
rtrn=2
2008-11-19 23:14:24 +03:00
;;
esac
exit $rtrn