#!/bin/bash
#
# This STONITH script drives the shared-storage stonith plugin.
#
# Author:	Lars Marowsky-Bree
# Copyright:	2008 Lars Marowsky-Bree
# License:      GNU General Public License (GPL)
#

# Main code

if [ x$sbd_device = x ]; then
	if [ -f /etc/sysconfig/sbd ]; then
		source /etc/sysconfig/sbd
		sbd_device=$SBD_DEVICE
	fi
fi

SBD_DEVS=${sbd_device%;}

sbd_device=${SBD_DEVS//;/ -d }

case $1 in
gethosts)
    echo `sbd -d $sbd_device list | cut -f2 | sort | uniq`
    exit 0
    ;;
off|reset)
    message=$1
    case "$crashdump" in
	    yes|true|1|YES|TRUE|ja|on|ON) message="crashdump" ;;
    esac
    sbd -d $sbd_device message $2 $message
    exit $?
    ;;
status)
    if ! sbd -d $sbd_device list >/dev/null 2>&1 ; then
    	ha_log.sh err "sbd could not list nodes from $sbd_device"
    	exit 1
    fi
    exit 0
    ;;
on)
    exit 1
    ;;
getconfignames)
    echo "sbd_device crashdump"
    exit 0
    ;;
getinfo-devid)
    echo "Shared storage STONITH device"
    exit 0
    ;;
getinfo-devname)
    echo "Shared storage STONITH device"
    exit 0
    ;;
getinfo-devdescr)
    cat << DESC
sbd uses a shared storage device as a medium to communicate
fencing requests. This allows clusters without network power
switches; the downside is that access to the shared storage
device becomes a Single Point of Failure. 

It requires sbd to be configured on all nodes.

Please read http://linux-ha.org/wiki/SBD_Fencing!

DESC
    exit 0
    ;;
getinfo-devurl)
    echo "http://linux-ha.org/wiki/SBD_Fencing"
    exit 0
    ;;
getinfo-xml)
    cat << SSHXML
<parameters>

<parameter name="crashdump">
<content type="string" />
<shortdesc lang="en">
Crashdump instead of regular fence
</shortdesc>
<longdesc lang="en">
If SBD is given a fence command, this option will instead perform a
kernel crash of a reboot or power-off, which on a properly configured
system can lead to a crashdump for analysis.

This is less safe for production environments. Please use with caution
and for debugging purposes only.
</longdesc>
</parameter>

<parameter name="sbd_device" unique="1">
<content type="string" />
<shortdesc lang="en">
SBD device(s)
</shortdesc>
<longdesc lang="en">
The block device used for the SBD partition. Up to three
can be specified if separated by a semicolon. (Please check
the documentation if specifying two.)

If not specified, will default to the value from /etc/sysconfig/sbd.

</longdesc>
</parameter>
</parameters>
SSHXML
    exit 0
    ;;
*)
    exit 1
    ;;
esac
