Service startup of Oracle & stop script and boot self-startup (single instance)
Environment description:
ORACLE_SID= orcl
ORACLE_BASE=/oracle/app/oracle
ORACLE_HOME=/oracle/app/oracle/product/11.2.0/dbhome_1
(all of the following operations are performed with root)
1. Modify the Oracle system configuration file: / etc/oratab so that the dbstart and dbshut that come with Oracle will work.
# vi / etc/oratab, replace the corresponding module of ORACLE_SID:ORACLE_HOME:Y, as follows
Orcl:/oracle/app/oracle/product/11.2.0/dbhome_1:Y
two。 Create the file oracle under / etc/init.d/, as follows: (specify the ORA_HOME=XX path for the environment)
#! / bin/bash
# chkconfig:345 61 61
# description:Apache
#
# 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/app/oracle/product/11.2.0/dbhome_1
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
3. Change file permissions
# chmod 755 / etc/init.d/oracle
4. Add Servic
# chkconfig-- level 35 oracle on
5. You need to stop the database before shutting down or restarting the machine.
# ln-s / etc/init.d/oracle / etc/rc0.d/K01oracle / / shutdown
# ln-s / etc/init.d/oracle / etc/rc6.d/K01oracle / / restart
6. Usage
# service oracle start / / start oracle
# service oracle stop / / close oracle
# service oracle restart / / restart oracle
7. test