#!/bin/sh
# $Id$
#
# Description:	Example Oracle control script
#		(Based on dbora example in Oracle docs)
#		Requires: dbstart, dbshut from Oracle, oratab file
#		Modify as required
#
# Platform:	Unix
#
# Author:	High-Availability.Com Ltd
#

# 
# Oracle configuration (EDIT)
#
ORA_HOME="/u01/app/oracle/product/8.1.7"	# Oracle installation dir
ORACLE_OWNER="oracle"
ORA_LIST=""		# listener name, if used
#ORA_LIST="listener"	# Oracle default

#
# standard variables and functions
#
. /opt/HAC/bin/rsf.sh

service=${RSF_SERVICE:-"oracle"}	# edit for pre-1.3 releases

script="`basename $0`"

#
# args: <start|stop> [no_of_attempts]
#
state=$1		# starting or stopping?
attempts=${2:-'1'}	# no of attempts at this action

#
# you may or may not want this test
#
if [ ${attempts} -gt 3 ]; then
	# fail after three goes
	dated_echo "${service}: Too many retries on ${state}, aborting"
	exit 3	# abort code
fi

#
# decide action based on first argument
#
case "${state}" in

'start')
	if [ -f "${ORA_HOME}/bin/dbstart" ]; then
		dated_echo "Starting Oracle database"
		su - "${ORACLE_OWNER}" -c "${ORA_HOME}/bin/dbstart"
	fi
	if [ "${ORA_LIST}" != "" ]; then
		dated_echo "Starting Oracle listener"
		su - "${ORACLE_OWNER}" -c "lsnrctl start ${ORA_LIST}"
	fi
		
	;;

'stop')
	if [ -f "${ORA_HOME}/bin/dbshut" ]; then
		dated_echo "Stopping Oracle database"
		su - "${ORACLE_OWNER}" -c "${ORA_HOME}/bin/dbshut"
	fi
	if [ "${ORA_LIST}" != "" ]; then
		dated_echo "Stopping Oracle listener"
		su - "${ORACLE_OWNER}" -c "lsnrctl stop ${ORA_LIST}"
	fi
	;;

*)
	echo "Usage: $0 <start|stop>"
	exit ${RSF_WARN}	# warning code
	;;

esac

exit ${RSF_OK}	# OK code (default)
