[DRBD-cvs] svn commit by phil - r2741 - trunk/scripts - New init script for gentoo, provided by Martin Bene.

drbd-cvs at lists.linbit.com drbd-cvs at lists.linbit.com
Wed Feb 7 14:04:12 CET 2007


Author: phil
Date: 2007-02-07 14:04:10 +0100 (Wed, 07 Feb 2007)
New Revision: 2741

Modified:
   trunk/scripts/drbd.gentoo
Log:
New init script for gentoo, provided by Martin Bene.


Modified: trunk/scripts/drbd.gentoo
===================================================================
--- trunk/scripts/drbd.gentoo	2007-02-07 12:52:56 UTC (rev 2740)
+++ trunk/scripts/drbd.gentoo	2007-02-07 13:04:10 UTC (rev 2741)
@@ -1,54 +1,153 @@
 #!/sbin/runscript
 # Distributed under the terms of the GNU General Public License v2
-#
-# kindly provided by Ron O'Hara, see
-# http://thread.gmane.org/gmane.comp.linux.drbd/6429
+# Copright 2001-2007 LINBIT Information Technologies
+# Philipp Reisner, Lars Ellenberg
+# Original script adapted to gentoo environment
 
+
+depend() {
+	use logger
+	need net
+	before heartbeat
+	after sshd
+}
+
 opts="${opts} reload"
 
+DEFAULTFILE="/etc/conf.d/drbd"
 DRBDADM="/sbin/drbdadm"
 PROC_DRBD="/proc/drbd"
-MODPROBE="modprobe"
-RMMOD="rmmod"
+MODPROBE="/sbin/modprobe"
+RMMOD="/sbin/rmmod"
+UDEV_TIMEOUT=10
+ADD_MOD_PARAM=""
 
-depend() {
-	use logger
-	need net
+if [ -f $DEFAULTFILE ]; then
+  . $DEFAULTFILE
+fi
+
+# Just in case drbdadm want to display any errors in the configuration
+# file, or we need to ask the user about registering this installation
+# at http://usage.drbd.org, we call drbdadm here without any IO
+# redirection.
+$DRBDADM sh-nop
+
+function assure_module_is_loaded
+{
+    [ -e "$PROC_DRBD" ] && return
+    ebegin "Loading drbd module"
+    ret=0
+
+    $MODPROBE -s drbd `$DRBDADM sh-mod-parms` $ADD_MOD_PARAM || ret=20
+    eend $ret
+    return $ret
 }
 
+function adjust_with_progress
+{
+    IFS_O=$IFS
+    NEWLINE='
+'
+    IFS=$NEWLINE
+    local D=0
+    local S=0
+    local N=0
+
+    einfon "Setting drbd parameters "
+    COMMANDS=`$DRBDADM -d adjust all` || { 
+    	eend 20 "Error executing drbdadm"
+	return 20 
+    }
+    echo -n "[ "
+
+    for CMD in $COMMANDS; do
+        if echo $CMD | grep -q disk; then echo -n "d$D "; D=$(( D+1 ));
+        elif echo $CMD | grep -q syncer; then echo -n "s$S "; S=$(( S+1 ));
+        elif echo $CMD | grep -q net; then echo -n "n$N "; N=$(( N+1 ));
+        else echo echo -n ".. ";
+        fi
+        IFS=$IFS_O
+        $CMD || {
+	    echo 
+            eend 20 "cmd $CMD failed!"
+	    return 20
+        }
+        IFS=$NEWLINE
+    done
+    echo "]"
+    eend 0
+
+    IFS=$IFS_O
+}
+
 start() {
-	ebegin "Starting DRBD"
-	# strange that gentoo thinks this should be done by an init script
-	for i in `seq 0 15` ; do
-	    test -b /dev/drbd$i || mknod -m 0660 /dev/drbd$i b 147 $i;
-	done
-	${DRBDADM} up all
-#	/sbin/drbdadm wait-connect all
+	einfo "Starting DRBD resources:"
+	eindent
+	assure_module_is_loaded || return $?
+	adjust_with_progress || return $?
+
+        # make sure udev has time to create the device files
+	ebegin "Waiting for udev device creation ..."
+        for RESOURCE in `$DRBDADM sh-resources`; do
+            for DEVICE in `$DRBDADM sh-dev $RESOURCE`; do
+                UDEV_TIMEOUT_LOCAL=$UDEV_TIMEOUT
+                while [ ! -e $DEVICE ] && [ $UDEV_TIMEOUT_LOCAL -gt 0 ] ; do
+                    sleep 1
+                UDEV_TIMEOUT_LOCAL=$(( $UDEV_TIMEOUT_LOCAL-1 ))
+                done
+            done
+        done
+	eend 0
+
+	einfon "Waiting for connection "
+	$DRBDADM wait-con-int
+	echo 
+	ret=$?
 	eend $ret
+	return $ret
 }
 
 stop() {
-	ebegin "Stopping DRBD"
-	${DRBDADM} down all
-	eend $?
+
+	ebegin "Stopping all DRBD resources"
+
+        # Check for mounted drbd devices
+        if ! grep -q '^/dev/drbd' /proc/mounts &>/dev/null; then
+                if [ -e ${PROC_DRBD} ]; then
+                        ${DRBDADM} down all
+                        ${RMMOD} drbd
+                fi
+		ret=$?
+                eend $ret
+		return $ret
+        else
+                einfo "drbd devices mounted, please umount them before trying to stop drbd!"
+                eend 1
+		return 1
+        fi
 }
 
 status() {
 	# NEEDS to be heartbeat friendly...
 	# so: put some "OK" in the output.
-	ebegin "Status of DRBD"
-	if [ -e $PROC_DRBD ]; then
-	    echo "drbd driver OK; device status:"
-	    cat "$PROC_DRBD"
-	    eend 0
-	else
-	    echo >&2 "drbd not loaded"
-	    eend 3
-	fi
+
+        if [ -e $PROC_DRBD ]; then
+	    ret=0
+            ebegin "drbd driver loaded OK; device status:"
+	    eend $ret
+            cat $PROC_DRBD
+        else
+	    ebegin "drbd not loaded"
+	    ret=3
+	    eend $ret
+        fi
+	return $ret
 }
 
 reload() {
 	ebegin "Reloading DRBD"
 	${DRBDADM} adjust all
-	eend $?
+	ret=$?
+	eend $ret
+	return $ret
 }



More information about the drbd-cvs mailing list