Whenever i am asked to implement start and stop scripts for an Oracle environment. I use these good old scripts to support the need for most systems.
These scripts use profiles for every ORACLE_HOME and ORACLE_SID.
Beside the start and stop purpose , they can also be used to just “set” the Oracle environment right for whatever you like to do.
So here is what i do;
First i create the profile files for every environment :
Environment file for an infrastrcuture DATABASE , profile_SID
PATH=/home/oracle/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin:/usr/games:/opt/gnome/bin:/opt/kde3/bin ; export PATH
ORACLE_HOME=/u00/app/oracle/product/10.1.4/idm ; export ORACLE_HOME
ORACLE_SID=SID ; export ORACLE_SID
PATH=$ORACLE_HOME/bin:$PATH ; export PATH
SCRIPT_DIR=/home/oracle/scripts ; export SCRIPT_DIR
Environment file for an INFRASTRUCTURE , profile_IDM
PATH=/home/oracle/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin:/usr/games:/opt/gnome/bin:/opt/kde3/bin ; export PATH
ORACLE_HOME=/u00/app/oracle/product/10.1.4/idm ; export ORACLE_HOME
ORACLE_SID=idm101 ; export ORACLE_SID
PATH=$ORACLE_HOME/bin:$PATH ; export PATH
SCRIPT_DIR=/home/oracle/scripts ; export SCRIPT_DIR
Environment file for a MIDTIER , profile_MID
PATH=/home/oracle/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin:/usr/games:/opt/gnome/bin:/opt/kde3/bin ; export PATH
ORACLE_HOME=/u00/app/oracle/product/10.1.2/mid ; export ORACLE_HOME
ORACLE_SID=mid101 ; export ORACLE_SID
PATH=$ORACLE_HOME/bin:$ORACLE_HOME/opmn/bin:$PATH ; export PATH
SCRIPT_DIR=/home/oracle/scripts
After creating the profiles we are ready to start using the actual start and stop scripts which use these profiles to set the right environment.
Start script for an INFRASTRUCTURE , start_idm101.sh
#######################################################################
#
# Script for starting an infrastructure
#
# Author : John Paul van Helvoort
# dd : 9-12-2008
#
#######################################################################
. /home/oracle/scripts/profile_SID
lsnrctl start
sqlplus /nolog <<EOF
conn / as sysdba
startup
exit
EOF
. /home/oracle/scripts/profile_IDM
$ORACLE_HOME/opmn/bin/opmnctl startall
$ORACLE_HOME/bin/emctl start iasconsole
Stop script for an INFRASTRUCTURE , stop_idm101.sh
#######################################################################
#
# Script for starting an infrastructure
#
# Author : John Paul van Helvoort
# dd : 9-12-2008
#######################################################################
. /home/oracle/scripts/profile_IDM
$ORACLE_HOME/bin/emctl stop iasconsole
$ORACLE_HOME/opmn/bin/opmnctl stopall
. /home/oracle/scripts/profile_SID
lsnrctl stop
sqlplus /nolog <<EOF
conn / as sysdba
shutdown immediate
exit
EOF
Start script for a MIDTIER , start_mid101.sh
#######################################################################
#
# Script for starting an midtier
#
# Author : John Paul van Helvoort
# dd : 9-12-2008
#######################################################################
. /home/oracle/scripts/profile_MID
$ORACLE_HOME/opmn/bin/opmnctl startall
$ORACLE_HOME/bin/emctl start iasconsole
Stop script for MIDTIER , stop_mid101.sh
#######################################################################
#
# Script for starting an midtier
#
# Author : John Paul van Helvoort
# dd : 9-12-2008
#######################################################################
. /home/oracle/scripts/profile_MID
$ORACLE_HOME/bin/emctl stop iasconsole
$ORACLE_HOME/opmn/bin/opmnctl stopall
The scripts to start and stop the Oracle components are ready. If you like to use these scripts to start and stop your Oracle environment upon booting and shutting the system.
You can follow up on the next script.
Create a file called /etc/init.d/oracle as the user root.
Put this in the script ( please check the path to the scripts called for here )
#! /bin/sh
#
# Author: John Paul van Helvoort
#
# /etc/rc.d/oracle
#
#
case "$1" in
start)
echo -n "Starting Oracle Components"
echo ""
/bin/su - oracle -c "/home/oracle/scripts/start_idm101.sh"
/bin/sleep 10
/bin/su - oracle -c "/home/oracle/scripts/start_mid101.sh"
;;
stop)
echo -n "Shutting Oracle Components"
/bin/su - oracle -c "/home/oracle/scripts/stop_mid101.sh"
/bin/sleep 10
/bin/su - oracle -c "/home/oracle/scripts/stop_idm101.sh"
;;
try-restart)
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|status|try-restart|restart}"
exit 1
;;
esac
exit
After this you need to create symbolic links from the correct runlevel directory to this /etc/init.d/oracle file.
Say your server uses runlevel 3 ( you can check this by viewing /etc/inittab on SLES ).
Go to /etc/init.d/rc3.d
ln -s /etc/init.d/oracle S99oracle
( S99 , being the last process to be started by the server )
ln -s /etc/init.d/oracle K01oracle
( K01 , being the first process to be killed by the server )