2 # Copyright 1999-2014 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License, v2 or later
5 extra_started_commands="reload"
14 DEFAULTFILE="/etc/conf.d/drbd"
15 DRBDADM="/sbin/drbdadm"
16 PROC_DRBD="/proc/drbd"
17 MODPROBE="/sbin/modprobe"
22 if [ -f $DEFAULTFILE ]; then
26 # Just in case drbdadm want to display any errors in the configuration
27 # file, or we need to ask the user about registering this installation
28 # at http://usage.drbd.org, we call drbdadm here without any IO
32 assure_module_is_loaded() {
33 [ -e "$PROC_DRBD" ] && return
34 ebegin "Loading drbd module"
37 $MODPROBE -s drbd `$DRBDADM sh-mod-parms` $ADD_MOD_PARAM || ret=20
42 adjust_with_progress() {
51 einfon "Setting drbd parameters "
52 COMMANDS=`$DRBDADM -d adjust all` || {
53 eend 20 "Error executing drbdadm"
58 for CMD in $COMMANDS; do
59 if echo $CMD | grep -q disk; then echo -n "d$D "; D=$(( D+1 ));
60 elif echo $CMD | grep -q syncer; then echo -n "s$S "; S=$(( S+1 ));
61 elif echo $CMD | grep -q net; then echo -n "n$N "; N=$(( N+1 ));
62 else echo echo -n ".. ";
67 eend 20 "cmd $CMD failed!"
79 einfo "Starting DRBD resources:"
81 assure_module_is_loaded || return $?
82 adjust_with_progress || return $?
84 # make sure udev has time to create the device files
85 ebegin "Waiting for udev device creation ..."
86 for RESOURCE in `$DRBDADM sh-resources`; do
87 for DEVICE in `$DRBDADM sh-dev $RESOURCE`; do
88 UDEV_TIMEOUT_LOCAL=$UDEV_TIMEOUT
89 while [ ! -e $DEVICE ] && [ $UDEV_TIMEOUT_LOCAL -gt 0 ] ; do
91 UDEV_TIMEOUT_LOCAL=$(( $UDEV_TIMEOUT_LOCAL-1 ))
97 einfon "Waiting for connection "
104 einfon "Become primary if configured "
105 $DRBDADM sh-b-pri all
113 ebegin "Stopping all DRBD resources"
115 # Check for mounted drbd devices
116 if ! grep -q '^/dev/drbd' /proc/mounts &>/dev/null; then
117 if [ -e ${PROC_DRBD} ]; then
121 if [ -e /proc/modules ] && grep -q '^drbd' /proc/modules ; then
128 einfo "drbd devices mounted, please umount them before trying to stop drbd!"
135 # NEEDS to be heartbeat friendly...
136 # so: put some "OK" in the output.
138 if [ -e $PROC_DRBD ]; then
140 ebegin "drbd driver loaded OK; device status:"
144 ebegin "drbd not loaded"
152 ebegin "Reloading DRBD"
153 ${DRBDADM} adjust all