How to Automate Startup/Shutdown of Oracle Database on Linux [ID 222813.1] | |||||
Modified 22-NOV-2010 Type BULLETIN Status PUBLISHED |
In this Document
Purpose
Scope and Application
How to Automate Startup/Shutdown of Oracle Database on Linux
References
<SID>:<ORACLE_HOME>:Ywhere Y states that the database can be started up and shutdown using
/etc/init.d/dboraNote: In Red Hat Advanced Server 2.1, the /etc/init.d is is a symbolic link to /etc/rc.d/init.d
Content of the script is as follows:
#!/bin/bash # # chkconfig: 2345 99 10 # description: Starts and stops Oracle processes # # 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=<Type your ORACLE_HOME in full path here> ORA_OWNER=<Type your Oracle account name here> case "$1" in 'start') # Start the TNS Listener su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" # Start the Oracle databases: # The following command assumes that the oracle login # will not prompt the user for any values su - $ORA_OWNER -c $ORA_HOME/bin/dbstart # Start the Intelligent Agent if [ -f $ORA_HOME/bin/emctl ]; then su - $ORA_OWNER -c "$ORA_HOME/bin/emctl start agent" elif [ -f $ORA_HOME/bin/agentctl ]; then su - $ORA_OWNER -c "$ORA_HOME/bin/agentctl start" else su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl dbsnmp_start" fi # Start Management Server if [ -f $ORA_HOME/bin/emctl ]; then su - $ORA_OWNER -c "$ORA_HOME/bin/emctl start dbconsole" elif [ -f $ORA_HOME/bin/oemctl ]; then su - $ORA_OWNER -c "$ORA_HOME/bin/oemctl start oms" fi # Start HTTP Server if [ -f $ORA_HOME/Apache/Apache/bin/apachectl ]; then su - $ORA_OWNER -c "$ORA_HOME/Apache/Apache/bin/apachectl start" fi touch /var/lock/subsys/dbora ;; 'stop') # Stop HTTP Server if [ -f $ORA_HOME/Apache/Apache/bin/apachectl ]; then su - $ORA_OWNER -c "$ORA_HOME/Apache/Apache/bin/apachectl stop" fi # Stop the TNS Listener su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" # Stop the Oracle databases: # The following command assumes that the oracle login # will not prompt the user for any values su - $ORA_OWNER -c $ORA_HOME/bin/dbshut rm -f /var/lock/subsys/dbora ;; esac # End of script dbora
or
#! /bin/sh # # MEmes: 03/07/2011: Oracle SysV script # # chkconfig: 2345 98 2 # description: Oracle database start/stop script ### BEGIN INIT INFO # Provides: oracle # Required-Start: $network # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Oracle database start/stop script # Description: Automatically starts/stops oracle instance ### END INIT INFO ORACLE_USER=${ORACLE_USER:-oracle} ORACLE_SID=${ORACLE_SID:-oracle} ORAENV_ASK=NO PATH=/usr/local/bin:/usr/bin:/bin [ -r /usr/local/bin/oraenv ] && . /usr/local/bin/oraenv > /dev/null 2>/dev/null . /etc/rc.d/init.d/functions prep () { # Test for valid ORACLE_HOME if [ ! -d "${ORACLE_HOME}" ]; then failure $"ORACLE_HOME is not a valid directory: ${ORACLE_HOME}" echo exit 1 fi # Test for SQL*Plus executable SQLPLUS=${SQLPLUS:-"${ORACLE_HOME}/bin/sqlplus"} if [ ! -x "${SQLPLUS}" ]; then failure $"Cannot locate SQL*Plus executable: ${SQLPLUS}" echo exit 1 fi # Test for lsnrctl executable LSNRCTL=${LSNRCTL:-"${ORACLE_HOME}/bin/lsnrctl"} if [ ! -x "${LSNRCTL}" ]; then failure $"Cannot locate lsnrctl executable: ${LSNRCTL}" echo exit 1 fi return 0 } startup () { # Modify network to reflect current hostname #sed -i -e "s/HOST = [^)]*/HOST = $(hostname -f)/g" ${ORACLE_HOME}/network/admin/tnsnames.ora #sed -i -e "s/HOST = [^)]*/HOST = $(hostname -f)/g" ${ORACLE_HOME}/network/admin/listener.ora # Start Oracle database and listener echo -n $"Starting Oracle DB: " su -c "${SQLPLUS} /nolog" ${ORACLE_USER} > /dev/null 2>&1 <<EOF connect / as sysdba startup exit EOF success echo echo -n $"Starting Oracle Listener: " su -c "${LSNRCTL} start" ${ORACLE_USER} > /dev/null 2>&1 success echo } shutdown () { # Shutdown Oracle listener and database echo -n $"Stopping Oracle Listener: " su -c "${LSNRCTL} stop" ${ORACLE_USER} > /dev/null 2>&1 success echo echo -n $"Stopping Oracle DB: " su -c "${SQLPLUS} /nolog" ${ORACLE_USER} > /dev/null 2>&1 <<EOF connect / as sysdba shutdown immediate exit EOF success echo } case "$1" in start) # Oracle listener and instance startup prep startup ;; stop) # Oracle listener and instance shutdown prep shutdown ;; reload|restart) prep shutdown startup ;; *) echo "Usage: $(basename $0) start|stop|restart|reload" exit 1 esac exit 0
NOTE1:
The lines:
# chkconfig: 35 99 10 # description: Starts and stops Oracle databaseare mandatory since they describe the characteristics of the service where:
chmod 755 /etc/init.d/dbora
This action registers the service to the Linux service mechanism. On SuSE SLES7 and Red Hat Advanced Server 2.1 it will arrange symbolic links under rc<runlevel>.d directories to /etc/init.d/dbora script./sbin/chkconfig --add dbora
### BEGIN INIT INFO # Provides: dbora # Required-Start: $local_fs $remote_fs $netdaemons # Required-Stop: # Default-Start: 3 5 # Default-Stop: 0 1 2 3 4 5 6 # Description: Oracle Startup ### END INIT INFOOn SuSE SLES7 the following symbolic links are created:
/sbin/chkconfig --set dbora 35After this action, the following symbolic links will be created pointing to /etc/init.d/dbora script:
Related
Products
|