Sophie

Sophie

distrib > Mandriva > 2006.0 > x86_64 > by-pkgid > 7ef7a2fe03574fcc794bfeef1f1eb977 > files > 1

drbd-utils-heartbeat-0.7.19-2.1.20060mdk.x86_64.rpm

#!/bin/bash
#
# This script is inteded to be used as resource script by heartbeat
#
# Jan 2003 by Philipp Reisner.
#
###

DEFAULTFILE="/etc/default/drbd"
DRBDADM="/usr/sbin/drbdadm"

if [ -f $DEFAULTFILE ]; then
  . $DEFAULTFILE
fi

if [ "$#" -eq 2 ]; then
  RES="$1"
  CMD="$2"
else
  RES="all"
  CMD="$1"
fi

case "$CMD" in
    start)
	# try several times, in case heartbeat deadtime
	# was smaller than drbd ping time
	try=6
	while true; do
		$DRBDADM primary $RES && break
		let "--try" || exit 20
		sleep 1
	done
	;;
    stop)
	# exec, so the exit code of drbdadm propagates
	exec $DRBDADM secondary $RES
	;;
    status)
	if [ "$RES" = "all" ]; then
	    echo "A resource name is required for status inquiries."
	    exit 10
	fi
	ST=$( $DRBDADM state $RES 2>&1 )
	STATE=${ST%/*}
	if [ "$STATE" = "Primary" ]; then
	    echo "running"
	elif [ "$STATE" = "Secondary" ]; then
	    echo "stopped"
	else
	    echo "$ST"
	fi
	;;
    *)
	echo "Usage: drbddisk [resource] {start|stop|status}"
	exit 1
	;;
esac

exit 0