#!/bin/bash
#
# enbd-secondary	Failover an ENBD RAID-1 device
#
# Author:	Steve Purkis <steve.purkis@multimap.com>
#		(derived work)
# Originals by:	Peter T. Breuer <ptb@it.uc3m.es>
#		Matthew Sackman <matthew@wellquite.org>
# License:	GNU GPL v2.1
#
# These scripts are for Red Hat machines.
# Designed to be used with Linux-HA (aka Heartbeat).
#
# Description:
# 'enbd-primary' service for failover with heartbeat.  This service should be
# configured to run on the secondary server by default.  It will be run on the
# primary server when the secondary goes down.  Because of this, the script
# must act as two different scripts, depending on which host it is running.

# Source RedHat function library.
. /etc/init.d/functions

# Source primary & secondary functions:
. /etc/ha.d/resource.d/enbd-primary-funcs
. /etc/ha.d/resource.d/enbd-secondary-funcs

# These should match 'uname -n'
PRIMARY="p4test1.multimap.com"
SECONDARY="p4test2.multimap.com"

case "$1" in
    start)
        case  `uname -n` in
	    $SECONDARY) start_secondary ;;
	    $PRIMARY) primary_takeover_secondary ;;
        esac
    ;;
    stop)
        case  `uname -n` in
	    $SECONDARY) stop_secondary ;;
	    $PRIMARY) primary_giveback_secondary ;;
        esac
    ;;
    *)
	echo "Usage: $0 {start|stop}"
	RETVAL=1
    ;;
esac

exit $RETVAL

