[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[lvm-devel] New clvmd init script



Hi guys,

Started from https://bugzilla.redhat.com/show_bug.cgi?id=533247

- fix whitespaces all over (tabs/spaces)
- use secure path
- remove hardcoding of paths for tools
- 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
- drop wait_for_finish. According to docs killproc will send first
specified signals and then SIGKILL and do the way for us.
- improve output from status
- make the init script lsb compliant

Please review and let me know if we need to add more changes.

Both Chrissie and I have tested this new version.

Fabio
diff --git a/scripts/clvmd_init_red_hat.in b/scripts/clvmd_init_red_hat.in
index e7d3871..8266c42 100644
--- a/scripts/clvmd_init_red_hat.in
+++ b/scripts/clvmd_init_red_hat.in
@@ -1,171 +1,150 @@
 #!/bin/bash
 #
+# clvmd - Clustered LVM Daemon init script
+#
 # chkconfig: - 24 76
 # description: Starts and stops clvmd
 #
 # For Red-Hat-based distributions such as Fedora, RHEL, CentOS.
-#	       
+#
 ### BEGIN INIT INFO
-# Provides: clvmd
-# Required-Start: $local_fs
-# Required-Stop: $local_fs
+# Provides:		clvmd
+# Required-Start:	$local_fs
+# Required-Stop:	$local_fs
 # Default-Start:
-# Default-Stop: 0 1 6
-# Short-Description: Clustered LVM Daemon
+# Default-Stop:
+# Short-Description:	Starts and stops clvmd
+# Description:		Starts and stops the Clustered LVM Daemon
 ### END INIT INFO
 
-. /etc/init.d/functions
+. /etc/rc.d/init.d/functions
 
 DAEMON=clvmd
 
 exec_prefix= exec_prefix@
 sbindir= sbindir@
 
-LVDISPLAY=${sbindir}/lvdisplay
-VGCHANGE=${sbindir}/vgchange
-VGSCAN=${sbindir}/vgscan
-VGDISPLAY=${sbindir}/vgdisplay
-VGS=${sbindir}/vgs
+# Set secure path
+PATH="${sbindir}:$PATH"
 
-CLVMDOPTS="-T20"
+CLVMDOPTS="-T30"
 
 [ -f /etc/sysconfig/cluster ] && . /etc/sysconfig/cluster
+[ -f /etc/sysconfig/$DAEMON ] && . /etc/sysconfig/$DAEMON
 
 [ -n "$CLVMD_CLUSTER_IFACE" ] && CLVMDOPTS="$CLVMDOPTS -I $CLVMD_CLUSTER_IFACE" 
 
 LOCK_FILE="/var/lock/subsys/$DAEMON"
 
-start()
-{
-	for rtrn in 0
-	do
-		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
+clustered_vgs() {
+	vgdisplay 2>/dev/null | \
+		awk 'BEGIN {RS="VG Name"} {if (/Clustered/) print $1;}'
+}
+
+clustered_lvs() {
+	for i in $(clustered_vgs); do
+		lvs -o lv_name --noheadings $i
 	done
+}
 
-	return $rtrn
+rh_status() {
+	status $DAEMON
 }
 
-stop()
+rh_status_q() {
+	rh_status >/dev/null 2>&1
+}
+
+start()
 {
-	for rtrn in 0
-	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=$?
+	if ! rh_status_q; then
+		echo -n "Starting $DAEMON: "
+		daemon $DAEMON $CLVMDOPTS || return $?
 		echo
-	done
-	
-	return $rtrn
+	fi
+
+	# NOTE: we use vgscan > /dev/null 2>&1 to hide some scary warnings.
+	# The following would be better.
+	# action "Refreshing VG cache:" vgscan
+
+	vgscan > /dev/null 2>&1
+
+	action "Activating VG $vg:" vgchange -ayl $LVM_VGS || return $?
+
+	touch $LOCK_FILE
+
+	return 0
 }
 
-wait_for_finish()
+stop()
 {
-	count=0
+	rh_status_q || return 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
-}
+	[ -z "$LVM_VGS" ] && LVM_VGS="$(clustered_vgs)"
 
-reload() {
-	$DAEMON -R
-}
+	action "Deactivating VG $vg:" vgchange -anl $LVM_VGS || return $?
 
-rh_status() {
-	status $DAEMON
-}
+	echo -n "Stopping clvm:"
+	killproc $DAEMON -TERM
+	echo
 
-rh_status_q() {
-	rh_status >/dev/null 2>&1
+	rm -f $LOCK_FILE
+
+	return 0
 }
 
+reload() {
+	rh_status_q || exit 7
+	action "Reloading $DAEMON configuration: " $DAEMON -R || return $?
+}
 
-rtrn=1
+restart() {
+	stop
+	start
+}
 
 # See how we were called.
 case "$1" in
   start)
 	start
 	rtrn=$?
-	[ $rtrn = 0 ] && touch $LOCK_FILE
 	;;
 
   stop)
 	stop
 	rtrn=$?
-	[ $rtrn = 0 ] && rm -f $LOCK_FILE
 	;;
 
-  restart)
-	if stop
-	then
-		wait_for_finish
-		start
-	fi 
+  restart|force-reload)
+	restart
 	rtrn=$?
 	;;
 
+  condrestart|try-restart)
+	rh_status_q || exit 0
+	restart
+	rtrn=$? 
+	;;
+
   reload)
-	rh_status_q || exit 7
 	reload
+	rtrn=$?
 	;;
 
   status)
 	rh_status
 	rtrn=$?
-	vols=$( $LVDISPLAY -C --nohead 2> /dev/null | awk '($3 ~ /....a./) {print $1}' )
-	echo active volumes: ${vols:-"(none)"}
+	if [ $rtrn = 0 ]; then
+		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
 

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]