#!/bin/sh
#
#	$Id: Delay.in,v 1.2.2.1 2005/01/12 03:12:34 horms Exp $
#
#	This script is a test resource for introducing delay.
#
#	usage: $0  {start|stop|status|monitor}
#	usage: $0  delay {start|stop|status|monitor}
#	usage: $0  startdelay stopdelay {start|stop|status|monitor}
#
#	This is really a test resource script.
#

usage() {
  cat <<-!
	usage: $0 [delay [stopdelay]] {start|stop|status|monitor}";
  	$Id: Delay.in,v 1.2.2.1 2005/01/12 03:12:34 horms Exp $
	!
  exit 1
}

. /etc/ha.d/shellfuncs

VARLIB=/var/lib/heartbeat
VLFILE=$VARLIB/rsctmp/Delay


Delay_stat() {
    test -f $VLFILE

}

Delay_Status() {
  if
    Delay_stat
  then
    echo "Delay is running OK"
    exit 0
  else
    echo "Delay is not operational"
    exit 1
  fi
}

Delay_Start() {
  if
    Delay_stat
  then
    echo "Delay already running"
    return 0
  else
    touch $VLFILE
    rc=$?
    sleep $StartDelay
    return $rc
  fi
}

Delay_Stop() {
  if
    Delay_stat
  then
    unlink $VLFILE
    rc=$?
    sleep $StopDelay
    return $rc
  else
    echo "Delay already stopped"
    return 0
  fi
}


case $# in
  1)	StartDelay=30; StopDelay=30; op=$1;;
  2)	StartDelay=$1; StopDelay=$1; op=$2;;
  3)	StartDelay=$1; StopDelay=$2; op=$3;;
  *)	usage; exit 1;;
esac

case $op in
  start)		Delay_Start;;
  stop)			Delay_Stop;;
  status|monitor)	Delay_Status;;

  *)			usage
 			exit 1;;
esac
exit $?
