init script for Oracle infrastructure

I went crazy the other day looking for this, sure that I’d posted it somewhere. I was wrong, I had not. This script should be copied into /etc/init.d on a Red Hat Enterprise/CentOS system, given execute permissions and then enabled using chkconfig. This is a companion to another script I did that starts/stops the underlying database (this script still needs some code to test that the DB is live before it tries to start everything up, I’m working on that…).

#!/bin/bash
#
# chkconfig: 29 99 1
# description: init script to start/stop oracle AS 10g
#
# match these values to your environment:
export ORACLE_HOME=/u01/app/oracle/product/infra
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/opmn/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export JAVA_HOME=$ORACLE_HOME/jdk
export ORACLE_SID=inft
export ORACLE_USER=orainfra
#
# see how we are called:
case $1 in
    start)
    echo "Starting Oracle AS ..."
    su - $ORACLE_USER <<EOS
    opmnctl startall
    emctl start iasconsole
    #
EOS
    ;;
    stop)
    echo "Stopping Oracle AS ..."
    su - $ORACLE_USER <<EOS
    emctl stop iasconsole
    opmnctl stopall
    #
EOS
    ;;
    #
    *)
    echo "Usage: $0 {start|stop}"
    ;;
esac