#!/bin/sh
#
# oracle start/stop skript 
# ver. 1.07
# DaN - dan@deam.org
#
# Edit the /etc/oratab file. 
# Database entries in the oratab file appear in the following format: 
#    ORACLE_SID:ORACLE_HOME:{Y|N}
# where Y or N specifies whether you want the dbstart and dbshut
# scripts to start up and shut down the database.
#


. /etc/rc.config

# get environment (e.g. ORACLE_HOME)
# maybe you have to change this
. /etc/profile.d/oracle.sh

# Determine the base and follow a runlevel link name.
base=${0##*/}
link=${base#*[SK][0-9][0-9]}

# Force execution if not called by a runlevel directory.
test $link = $base && START_ORACLE="yes"
test "${START_ORACLE:-no}" = "yes" || exit 0

echo 750000000 >/proc/sys/kernel/shmmax

return=$rc_done
if [ ! -f $ORACLE_HOME/bin/dbstart -o -z "$ORA_OWNER" ];
then
    echo -n "Oracle could not be found (ORACLE_HOME wrong?)" 
    return=$rc_failed
    echo -e "$return"
    exit 1
fi

case "$1" in
	start)
	    # Start the Oracle databases:
	    echo "Starting Oracle:"
	    su - $ORA_OWNER -c "$ORACLE_HOME/bin/dbstart"
	    test "${START_LISTENER:-no}" = "yes" && su - $ORA_OWNER -c "$ORACLE_HOME/bin/lsnrctl start"
	    test "${START_AGENT:-no}"    = "yes" && su - $ORA_OWNER -c "$ORACLE_HOME/bin/lsnrctl dbsnmp_start"

	    # start WebDB listener
	    if [ -f $ORACLE_HOME/webdb/bin/wdbstart -a ${START_WEBDB:-no} = "yes" ]; then
		    if [ ${WEBDB_PORT:-80} -lt 1024 ]; then
			    $ORACLE_HOME/webdb/bin/wdbstart `hostname -f` ${WEBDB_PORT:-80} &
		    else
			    su - $ORA_OWNER -c "$ORACLE_HOME/webdb/bin/wdbstart `hostname -f` $WEBDB_PORT &"
		    fi
	    fi
	    echo -e "$return"
	    ;;
	stop)
	    # Stop the Oracle databases:
	    echo "Shutting down Oracle:"
	    if [ -f $ORACLE_HOME/webdb/bin/wdblsnr ]; then
		    killproc -t11 $ORACLE_HOME/webdb/bin/wdblsnr
	    fi
	    su - $ORA_OWNER -c "$ORACLE_HOME/bin/lsnrctl dbsnmp_stop"
	    su - $ORA_OWNER -c "$ORACLE_HOME/bin/lsnrctl stop"
	    su - $ORA_OWNER -c "$ORACLE_HOME/bin/dbshut"
	    echo -e "$return"
	    ;;
	reload)
	    ;;
	*)
	    echo "Usage: $0 {start|stop}"
	    exit 1
esac
test "$return" = "$rc_done" || exit 1
exit 0
