1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

- fix whitespaces all over (tabs/spaces)

- increase timeout to 30 secs (on Chrissie request)
- source both cluster and clvmd for options (like all the other cluster
  init scripts)
- add clustered_vgs and _lvs commodity fns
- move rh_status* fns at the top, so they can be reused
- heavily cleanup start and stop fns from redundant code and unnecessary
  loops
- improve output from different operations
- make the init script lsb compliant
- don´t force kill of the daemon, send only a TERM signal and then wait
for it to exit
- Resolves rhbz#533247
This commit is contained in:
Fabio M. Di Nitto 2010-02-26 13:07:43 +00:00
parent 65752052e1
commit 630e13edd8
2 changed files with 132 additions and 106 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.62 - Version 2.02.62 -
==================================== ====================================
Rewrite clvmd init script.
Remove lvs_in_vg_activated_by_uuid_only call. Remove lvs_in_vg_activated_by_uuid_only call.
Run device info query device by uuid only. Run device info query device by uuid only.
Don't touch /dev in vgmknodes if activation is disabled. Don't touch /dev in vgmknodes if activation is disabled.

View File

@ -1,121 +1,56 @@
#!/bin/bash #!/bin/bash
# #
# clvmd - Clustered LVM Daemon init script
#
# chkconfig: - 24 76 # chkconfig: - 24 76
# description: Starts and stops clvmd # description: Cluster daemon for userland logical volume management tools.
# #
# For Red-Hat-based distributions such as Fedora, RHEL, CentOS. # For Red-Hat-based distributions such as Fedora, RHEL, CentOS.
# #
### BEGIN INIT INFO ### BEGIN INIT INFO
# Provides: clvmd # Provides: clvmd
# Required-Start: $local_fs # Required-Start: $local_fs
# Required-Stop: $local_fs # Required-Stop: $local_fs
# Default-Start: # Short-Description: This service is Clusterd LVM Daemon.
# Default-Stop: 0 1 6 # Description: Cluster daemon for userland logical volume management tools.
# Short-Description: Clustered LVM Daemon
### END INIT INFO ### END INIT INFO
. /etc/init.d/functions . /etc/rc.d/init.d/functions
DAEMON=clvmd DAEMON=clvmd
exec_prefix=@exec_prefix@ exec_prefix=@exec_prefix@
sbindir=@sbindir@ sbindir=@sbindir@
LVDISPLAY=${sbindir}/lvdisplay lvm_vgchange=${sbindir}/vgchange
VGCHANGE=${sbindir}/vgchange lvm_vgdisplay=${sbindir}/vgdisplay
VGSCAN=${sbindir}/vgscan lvm_vgscan=${sbindir}/vgscan
VGDISPLAY=${sbindir}/vgdisplay lvm_lvs=${sbindir}/lvs
VGS=${sbindir}/vgs
CLVMDOPTS="-T20" CLVMDOPTS="-T30"
[ -f /etc/sysconfig/cluster ] && . /etc/sysconfig/cluster [ -f /etc/sysconfig/cluster ] && . /etc/sysconfig/cluster
[ -f /etc/sysconfig/$DAEMON ] && . /etc/sysconfig/$DAEMON
[ -n "$CLVMD_CLUSTER_IFACE" ] && CLVMDOPTS="$CLVMDOPTS -I $CLVMD_CLUSTER_IFACE" [ -n "$CLVMD_CLUSTER_IFACE" ] && CLVMDOPTS="$CLVMDOPTS -I $CLVMD_CLUSTER_IFACE"
# allow up to $CLVMD_STOP_TIMEOUT seconds to clvmd to complete exit operations
# default to 10 seconds
[ -z $CLMVD_STOP_TIMEOUT ] && CLVMD_STOP_TIMEOUT=10
LOCK_FILE="/var/lock/subsys/$DAEMON" LOCK_FILE="/var/lock/subsys/$DAEMON"
start() # NOTE: replace this with vgs, once display filter per attr is implemented.
{ clustered_vgs() {
for rtrn in 0 ${lvm_vgdisplay} 2>/dev/null | \
do awk 'BEGIN {RS="VG Name"} {if (/Clustered/) print $1;}'
if ! pidof $DAEMON > /dev/null
then
echo -n "Starting $DAEMON: "
daemon $DAEMON $CLVMDOPTS
rtrn=$?
echo
if [ $rtrn -ne 0 ]
then
break
fi
fi
# refresh cache
$VGSCAN > /dev/null 2>&1
if [ -n "$LVM_VGS" ]
then
for vg in $LVM_VGS
do
action "Activating VG $vg:" $VGCHANGE -ayl $vg || rtrn=$?
done
else
action "Activating VGs:" $VGCHANGE -ayl || rtrn=$?
fi
done
return $rtrn
} }
stop() clustered_lvs() {
{ for i in $(clustered_vgs); do
for rtrn in 0 ${lvm_lvs} -o lv_name --noheadings $i
do
if [ -n "$LVM_VGS" ]
then
for vg in $LVM_VGS
do
action "Deactivating VG $vg:" $VGCHANGE -anl $vg || rtrn=$?
done
else
# Hack to only deactivate clustered volumes
clustervgs=`$VGDISPLAY 2> /dev/null | awk 'BEGIN {RS="VG Name"} {if (/Clustered/) print $1;}'`
for vg in $clustervgs; do
action "Deactivating VG $vg:" $VGCHANGE -anl $vg || rtrn=$?
done
fi
[ $rtrn -ne 0 ] && break
echo -n "Stopping clvm:"
killproc $DAEMON -TERM
rtrn=$?
echo
done done
return $rtrn
}
wait_for_finish()
{
count=0
while [ "$count" -le 10 -a -n "`pidof $DAEMON`" ]
do
sleep 1
count=$((count + 1))
done
if [ `pidof $DAEMON` ]
then
return 1
else
return 0
fi
}
reload() {
$DAEMON -R
} }
rh_status() { rh_status() {
@ -126,46 +61,136 @@ rh_status_q() {
rh_status >/dev/null 2>&1 rh_status >/dev/null 2>&1
} }
start()
{
if ! rh_status_q; then
echo -n "Starting $DAEMON: "
daemon $DAEMON $CLVMDOPTS || return $?
echo
fi
rtrn=1 # 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.
${lvm_vgscan} > /dev/null 2>&1
action "Activating VG(s):" ${lvm_vgchange} -ayl $LVM_VGS || return $?
touch $LOCK_FILE
return 0
}
wait_for_finish()
{
count=0
while [ "$count" -le "$CLVMD_STOP_TIMEOUT" ] && \
rh_status_q ]; do
sleep 1
count=$((count+1))
done
! rh_status_q
}
stop()
{
rh_status_q || return 0
action "Deactivating clusterd VG(s):" ${lvm_vgchange} -anl ${LVM_VGS:-$(clustered_vgs)} || return $?
action "Signaling $DAEMON to exit" kill -TERM $(pidofproc $DAEMON) || return $?
# 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
return 1
else
echo -n "$DAEMON terminated"
success
echo
fi
rm -f $LOCK_FILE
return 0
}
reload() {
rh_status_q || exit 7
action "Reloading $DAEMON configuration: " $DAEMON -R || return $?
}
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.
stop && start
}
# See how we were called. # See how we were called.
case "$1" in case "$1" in
start) start)
start start
rtrn=$? rtrn=$?
[ $rtrn = 0 ] && touch $LOCK_FILE
;; ;;
stop) stop)
stop stop
rtrn=$? rtrn=$?
[ $rtrn = 0 ] && rm -f $LOCK_FILE
;; ;;
restart) restart|force-reload)
if stop restart
then
wait_for_finish
start
fi
rtrn=$? rtrn=$?
;; ;;
condrestart|try-restart)
rh_status_q || exit 0
restart
rtrn=$?
;;
reload) reload)
rh_status_q || exit 7
reload reload
rtrn=$?
;; ;;
status) status)
rh_status rh_status
rtrn=$? rtrn=$?
vols=$( $LVDISPLAY -C --nohead 2> /dev/null | awk '($3 ~ /....a./) {print $1}' ) if [ $rtrn = 0 ]; then
echo active volumes: ${vols:-"(none)"} cvgs="$(clustered_vgs)"
echo Active clustered Volume Groups: ${cvgs:-"(none)"}
clvs="$(clustered_lvs)"
echo Active clustered Logical Volumes: ${clvs:-"(none)"}
fi
;; ;;
*) *)
echo $"Usage: $0 {start|stop|restart|reload|status}" echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
rtrn=2
;; ;;
esac esac