Oracle provides the dbstart and dbshut scripts in the $ ORACLE_HOMEbin directory to start and stop Oracle. The dbstart script starts the specified database instance and Listen.
Oracle provides dbstart and dbshut scripts in the $ ORACLE_HOME/bin directory to start and stop Oracle. The dbstart script starts the specified database instance and Listen.
Environment
CentOS 6 x86_64, Oracle 11g R2
Solution
Oracle provides dbstart and dbshut scripts in the $ ORACLE_HOME/bin directory to start and stop Oracle. The dbstart script starts the specified database instance and Listener.
First, modify/etc/oratab and set the startup flag of the instance to "Y ".
ORA01:/home/oracle/app/oracle/product/11.2.0/dbhome_1: Y
Then, create the/etc/init. d/dbora script with the following content:
#! /Bin/bash
### BEGIN INIT INFO
# Provides: Oracle
# Required-Start: $ local_fs $ network $ remote_fs
# Required-Stop: $ local_fs $ network $ remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop oracle
# Description: Oracle is a damn RDBMS
### END INIT INFO
#
# Change the value of ORACLE_HOME to specify the correct Oracle home
# Directory for your installation.
ORACLE_HOME =/home/oracle/app/oracle/product/11.2.0/dbhome_1/
#
# Change the value of ORACLE_OWNER to the login name of
# Oracle owner at your site.
#
ORACLE_OWNER = "oracle"
LOCK_FILE = "/var/lock/subsys/dbora"
Case $1 in
'Start ')
Su-$ ORACLE_OWNER-c "$ ORACLE_HOME/bin/dbstart $ ORACLE_HOME &"
Touch $ LOCK_FILE
;;
'Stop ')
Su-$ ORACLE_OWNER-c "$ ORACLE_HOME/bin/dbshut $ ORACLE_HOME &"
Rm-f $ LOCK_FILE
;;
*)
Echo "usage: $0 {start | stop }"
Exit
;;
Esac
Exit
Add the execution permission to dbora:
Chmod a + x/etc/init. d/dbora
Add dbora to the self-starting service:
Chmod a + x/etc/init. d/dbora
In this way, Oracle can be automatically started and stopped as a system service.