15 March 2006
Automatic starting of Oracle components on Unix
General instructions:
Additional instructions forHP:
PATH=/usr/sbin:/usr/bin:/sbin:/usr/local/bin
PATH=$ORACLE_HOME/bin:$PATH
export PATH ORACLE_HOME
rval=0
set_return() {
x=$?
if [ $x -ne 0 ]; then
echo "EXIT CODE: $x"
rval=1 # script Failed
fi
}
case $1 in
'start_msg')
# Emit a _short_ message relating to running this script with
# the "start" argument; this message appears as part of the checklist.
echo "Starting the Oracle components"
;;
'stop_msg')
# Emit a _short_ message relating to running this script with
# the "stop" argument; this message appears as part of the checklist.
echo "Stopping the Oracle components"
;;
'start')
# source the system configuration variables
if [ -f /etc/rc.config ] ; then
. /etc/rc.config
else
echo "ERROR: /etc/rc.config defaults file MISSING"
fi
# Check to see if this script is allowed to run...
if [ "$ORACLE_CONTROL_VARIABLE" != 1 ]; then
rval=2
else
su - oracle -c dbstart
set_return
if [ $rval -eq 1 ]; then
echo "Oracle startup failed"
exit $rval
fi
su - oracle -c "$ORA_HOME/bin/lsnrctl start listener_oemp"
set_return
if [ $rval -eq 1 ]; then
echo "Oracle startup failed"
exit $rval
fi
fi
;;
'stop')
# source the system configuration variables
if [ -f /etc/rc.config ] ; then
. /etc/rc.config
else
echo "ERROR: /etc/rc.config defaults file MISSING"
fi
# Check to see if this script is allowed to run...
if [ "$ORACLE_CONTROL_VARIABLE" != 1 ]; then
rval=2
else
su - oracle -c dbshut; #Only db, listener is protected with pwd
set_return
if [ $rval -eq 1 ]; then
echo "Oracle shutdown failed"
exit $rval
fi
fi
;;
*)
echo "usage: $0 {start|stop|start_msg|stop_msg}"
rval=1
;;
esac
exit $rval
- Create a file called "oracle" in /etc/init.d for (Sun, Linux) or /sbin/init.d (HP).
- Create two soft links from rc.d directories (consult with your Unix admin for the priority numbers, 03 and 93 are used in this example):
- K03oracle -> /etc/init.d/oracle #Shut down when going to level 0
- S93oracle -> /etc/init.d/oracle # Startup when going to level 3
Additional instructions forHP:
- Create your "oracle" file from /sbin/init.d/template file. Below is the example of what your "oracle" file might look like
- Create a file /etc/rc.config.d/oracle with only one line:
- ORACLE_CONTROL_VARIABLE=1
- In the future, if you want to switch off automatic starting/shutting, just change ORACLE_CONTROL_VARIABLE to 0
PATH=/usr/sbin:/usr/bin:/sbin:/usr/local/bin
PATH=$ORACLE_HOME/bin:$PATH
export PATH ORACLE_HOME
rval=0
set_return() {
x=$?
if [ $x -ne 0 ]; then
echo "EXIT CODE: $x"
rval=1 # script Failed
fi
}
case $1 in
'start_msg')
# Emit a _short_ message relating to running this script with
# the "start" argument; this message appears as part of the checklist.
echo "Starting the Oracle components"
;;
'stop_msg')
# Emit a _short_ message relating to running this script with
# the "stop" argument; this message appears as part of the checklist.
echo "Stopping the Oracle components"
;;
'start')
# source the system configuration variables
if [ -f /etc/rc.config ] ; then
. /etc/rc.config
else
echo "ERROR: /etc/rc.config defaults file MISSING"
fi
# Check to see if this script is allowed to run...
if [ "$ORACLE_CONTROL_VARIABLE" != 1 ]; then
rval=2
else
su - oracle -c dbstart
set_return
if [ $rval -eq 1 ]; then
echo "Oracle startup failed"
exit $rval
fi
su - oracle -c "$ORA_HOME/bin/lsnrctl start listener_oemp"
set_return
if [ $rval -eq 1 ]; then
echo "Oracle startup failed"
exit $rval
fi
fi
;;
'stop')
# source the system configuration variables
if [ -f /etc/rc.config ] ; then
. /etc/rc.config
else
echo "ERROR: /etc/rc.config defaults file MISSING"
fi
# Check to see if this script is allowed to run...
if [ "$ORACLE_CONTROL_VARIABLE" != 1 ]; then
rval=2
else
su - oracle -c dbshut; #Only db, listener is protected with pwd
set_return
if [ $rval -eq 1 ]; then
echo "Oracle shutdown failed"
exit $rval
fi
fi
;;
*)
echo "usage: $0 {start|stop|start_msg|stop_msg}"
rval=1
;;
esac
exit $rval