Oracle startup/shutdown script on Redhat Linux

Write an article in the RTC installation process, because oracle is used, and oracle is manually installed by yourself, so there is no startup and shutdown script like other commercial software such as Omega and Landmark, but you can only write one yourself.

1. Modify /etc/oratab

#
# This file is used by ORACLE utilities.  It is created by root.sh
# and updated by the Database Configuration Assistant when creating
# a database.

# A colon, ':', is used as the field terminator.  A new line terminates
# the entry.  Lines beginning with a pound sign, '#', are comments.
#
# Entries are of the form:
#   $ORACLE_SID:$ORACLE_HOME:<N|Y>:
#
# The first and second fields are the system identifier and home
# directory of the database respectively.  The third filed indicates
# to the dbstart utility that the database should , "Y", or should not,
# "N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
CLMDB:/oracle/ora/ora11g:Y

Last line, last letter, changed from N to Y

2. Test dbstart, dbshut

First, ensure that dbstart and dbshut commands can be successfully executed:
su - oracle
dbshut
dbstart
must be executed normally without errors.

3. Edit the startup script

vi /etc/init.d/oracle

#!/bin/sh
# chkconfig: 35 99 01
# description: oracle

#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.
ORA_HOME=/oracle/ora/ora11g
ORA_OWNER=oracle
if [ ! -f $ORA_HOME/bin/dbstart ]
then
    echo "Oracle startup: cannot start"
    exit
fi
case "$1" in
'start')
# Start the Oracle databases:
echo "Starting Oracle Databases ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart" >>/var/log/oracle
echo "Done"

# Start the Listener:
echo "Starting Oracle Listeners ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" >>/var/log/oracle
echo "Done."
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Finished." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
touch /var/lock/subsys/oracle
;;

'stop')
# Stop the Oracle Listener:
echo "Stoping Oracle Listeners ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" >>/var/log/oracle
echo "Done."
rm -f /var/lock/subsys/oracle

# Stop the Oracle Database:
echo "Stoping Oracle Databases ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut" >>/var/log/oracle
echo "Done."
echo ""
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Finished." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
;;

'restart')
$0 stop
$0 start
;;
esac

Note: the first three lines, it is best not to modify:

#!/bin/sh
# chkconfig: 35 99 01
# description: oracle

chkconfig: 35 99 01
means to start oracle at level 3 and level 5,
Level 3 is Full multiuser mode
Level 5 is X11 graphics mode
99 means the boot sequence, try to start oracle at the end of boot, (of course you must use oracle service Start before other services)
01 is the order in which the script is executed when shutting down: set to 01 is to want to shut down oracle first, and then perform other shutdown operations.
description: The line of oracle
is also used for the management of the chkconfig command. It is best to keep the same name as the script file, so that it is not easy to make mistakes.
Then add execute permission to the script:
chmod 755 oracle

To add this add-on to the corresponding execution level, execute:
chkconfig –add oracle
View:
chkconfig –list oracle
If level 3 and 5 are not on, execute:
chkconifg –level 35 on The oracle
script will automatically link to the corresponding location, no need Manually go to the link:
/etc/rc0.d K01oracle -> ../init.d/oracle
/etc/rc3.d S99oracle -> ../init.d/oracle
/etc/rc5.d S99oracle -> ../ init.d/oracle
/etc/rc6.d K01oracle -> ../init.d/oracle

Before using it officially, please test it first:
service oracle start
service oracle stop
service oracle restart

4. Concerned about /var/lock/subsys

Create a file with the same name as the script in the /var/lock/subsys directory,
touch /var/lock/subsys/oracle
so that the shutdown script will be executed when shutdown, if there is no such file,
manually execute /etc// rc0.d/oracle stop is normal, but it cannot be executed during shutdown.

This step needs to be done with the script. Some do this step directly in the script. It should be noted that if the file name, service name or script content is modified, the files in the /var/lock/subsys/ directory and these names should be kept. consistency.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325198584&siteId=291194637