#!/bin/sh
#
#	$Id: Dummy.in,v 1.5 2006/07/27 09:19:36 andrew Exp $
#
#	Dummy OCF RA. Does nothing but wait a few seconds, can be
#	configured to fail occassionally.
#
# Copyright (c) 2004 SUSE LINUX AG, Lars Marowsky-Bre
#                    All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it would be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# Further, this software is distributed without any warranty that it is
# free of the rightful claim of any third person regarding infringement
# or the like.  Any license provided herein, whether implied or
# otherwise, applies only to this software file.  Patent licenses, if
# any, provided herein do not apply to combinations of this program with
# other software, or any other product whatsoever.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
#

#######################################################################
# Initialization:

. /usr/lib/heartbeat/ocf-shellfuncs

#######################################################################

meta_data() {
	cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="Dummy" version="0.9">
<version>1.0</version>

<longdesc lang="en">
This is a Dummy Resource Agent. It does absolutely nothing except wait
for various amounts of time on execution, and fail actions if it sees a
/tmp/Dummy.{start,stop,monitor,validate-all} around.
</longdesc>
<shortdesc lang="en">Dummy resource agent</shortdesc>

<parameters>
<parameter name="start_delay" unique="0">
<longdesc lang="en">
How long to delay on start.
</longdesc>
<shortdesc lang="en">Start delay</shortdesc>
<content type="integer" default="5" />
</parameter>

<parameter name="stop_delay" unique="0">
<longdesc lang="en">
How long to delay on stop.
</longdesc>
<shortdesc lang="en">Stop delay</shortdesc>
<content type="integer" default="5" />
</parameter>

<parameter name="monitor_delay" unique="0">
<longdesc lang="en">
How long to delay on monitor.
</longdesc>
<shortdesc lang="en">Monitor delay</shortdesc>
<content type="integer" default="2" />
</parameter>
</parameters>

<actions>
<action name="start"   timeout="90" />
<action name="stop"    timeout="100" />
<action name="monitor" depth="0"  timeout="20" interval="10" start-delay="1m" />
<action name="meta-data"  timeout="5" />
<action name="verify-all"  timeout="30" />
</actions>
</resource-agent>
END
}

#######################################################################

dummy_usage() {
	cat <<END
usage: $0 {start|stop|monitor|validate-all|meta-data}

Expects to have a fully populated OCF RA-compliant environment set.
END
}

dummy_exit() {
	if [ -e /tmp/Dummy.$__OCF_ACTION ]; then
		exit $OCF_ERR_GENERIC
	else
		exit $1
	fi
}

dummy_start() {
	sleep $OCF_RESKEY_start_delay
	if [ -f ${OCF_RESKEY_state} ]; then
	    return 0
	fi
	touch ${OCF_RESKEY_state}
}

dummy_stop() {
	sleep $OCF_RESKEY_stop_delay
	if [ -f ${OCF_RESKEY_state} ]; then
	    rm ${OCF_RESKEY_state}
	fi
	return 0
}

dummy_monitor() {
	sleep $OCF_RESKEY_monitor_delay
	if [ -f ${OCF_RESKEY_state} ]; then
	    return 0
	fi
	return 7
}

dummy_validate() {
	exit $OC_ERR_UNIMPLEMENTED
}

: ${OCF_RESKEY_start_delay=10}
: ${OCF_RESKEY_stop_delay=$OCF_RESKEY_start_delay}
: ${OCF_RESKEY_monitor_delay=$OCF_RESKEY_start_delay}
: ${OCF_RESKEY_state=/var/run/heartbeat/rsctmp/Dummy-${OCF_RESOURCE_INSTANCE}.state}

case $__OCF_ACTION in
meta-data)	meta_data
		exit $OCF_SUCCESS
		;;
start)		dummy_start
		dummy_exit $?
		;;
stop)		dummy_stop
		dummy_exit $?
		;;
monitor)	dummy_monitor
		dummy_exit $?
		;;
validate-all)	dummy_validate
		dummy_exit $?
		;;
usage|help)	dummy_usage
		exit $OCF_SUCCESS
		;;
*)		dummy_usage
		exit $OCF_ERR_UNIMPLEMENTED
		;;
esac

