Sunteți pe pagina 1din 4

Start Oracle Automatically on Linux To Start/Stop any of the user defined services/demons/applications/programs when ever we shutdown or restart Unix

server automatically, Please follow the below steps Basically its a 5 step process.

Step:2 => login as root and ma e your current directory as /etc/init.d Copy the below script/template and save it with a name under this directory (eg: myservices) Below script perfectly wor s for oracle startup and shutdown #!/bin/bash # ch config: 345 90 12 # description: start/stop myservices #******************************************************************************* ************ # Script : myservices # Version : 1.0 #----------------------------------------------------------------------# History of changes #----------------------------------------------------------------------# Date Version Author Description # --------- ------- -------- -----------------------------------------# The service will be enabled by default for runlevels 3,4 and 5. # The 90 is the start priority. # The 12 is the stop priority. # The lower the number the higher the priority # and the sooner a service will be started/stopped. # # Return values for all commands: # 0 - success # 1 - generic or unspecified error #******************************************************************************* ************ # Source function library. . /etc/init.d/functions # Set the environment variables export ORACLE_BASE=/dbase/app/oracle export ORACLE_HOME=/dbase/app/oracle/product/11.2.0/db_1 export JAVA_HOME=$ORACLE_HOME/jd export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin:$JAVA_HOME/bin export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib:/usr/local/lib:/usr/lib :/usr/lib/libnetsnmpj.so export TMPDIR=/tmp export TMP=/tmp # Set ORA_HOME to be equivalent to the $ORACLE_HOME from which you wish to execu te dbstart and dbshut; # Set ORA_OWNER to the user id of the owner of the Oracle database in ORA_HOME. # dbstart and dbshut will ta ecare of LISTENER ORA_HOME=/dbase/app/oracle/product/11.2.0/db_1 ORA_OWNER=oracle # Set variables

Step:1 => We should have root permissions to implement this tas

CURDATE=`date | aw '{print $3$2$6}'` START_LOG=/var/log/start_${CURDATE}.log START_ERR=/var/log/start_${CURDATE}.err STOP_LOG=/var/log/stop_${CURDATE}.log STOP_ERR=/var/log/stop_${CURDATE}.err isRunning() { ps -ed | grep -i $1 | wc -l | aw }

getPid() { ps -ed | grep -i $1 | aw '{print $1}' } start() { echo "========================================================================== =============" >> $START_LOG echo "MYSERVICES-START: `date`" >> ${START_LOG} echo "========================================================================== =============" >> $START_LOG #Quit if dbstart script doesnt exists if [ ! -f $ORA_HOME/bin/dbstart ] then echo "myservices cannot start:: dbstart not found!" | tee -a $START_LOG RETVAL=1 failure $"myservices startup oracleDatabase" else # su will not prompt the user for any values echo "myservices:: starting oracleDatabase" | tee -a $START_LOG su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME" >> $START_LOG success $"myservices startup" RETVAL=0 success $"myservices startup oracleDatabase" fi echo "========================================================================== =============" >> $START_LOG # Touch the loc file touch /var/loc /subsys/myservices echo return $RETVAL } stop() { echo "========================================================================== =============" >> $STOP_LOG echo "MYSERVICES-STOP: `date`" >> $STOP_LOG echo "========================================================================== =============" >> $STOP_LOG #Quit if dbshut script doesnt exists if [ ! -f $ORA_HOME/bin/dbshut ] then echo "myservices cannot stop oracleDatabase:: dbshut not found!" | tee -a $STOP_ LOG RETVAL=1

'{print $1}'

failure $"myservices stop oracleDatabase" else echo "myservices:: stoping oracleDatabase" | tee -a $STOP_LOG su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut $ORA_HOME" >> $STOP_LOG RETVAL=0 success $"myservices stop oracleDatabase" fi echo "========================================================================== =============" >> $STOP_LOG # Remove the loc file rm -f /var/loc /subsys/myservices echo return $RETVAL } status() { myStatus=`isRunning oracle` if [ ${myStatus} -gt 0 ]; then success echo "oracle Up!" else echo "oracle Down!" fi echo } case "$1" in start) start ;; stop) stop ;; status) status ;; restart|reload) stop start ;; *) echo $"Usage: $0 {start|stop|restart|reload|status}" exit 1 esac exit $? Step:3 => Grant execute permissions and Register the script to the appropriate r unlevels #cd /etc/init.d #chmod 755 myservices #ch config --level 345 myservices on Step:4 => Once the above command is executed, Verify/validate it with below comm and. We should see output as follows #ch config --list myservices myservices 0:off 1:off 2:off 3:on 4:on 5:on 6:off Step:5 => Restart the machine and test it.

Detailed description of step 3: It will create soft lin s in the runlevel folders. The soft lin name starts wit h S=>Start/K=>Kill and followed by priority and finally followed by our script n ame. rc.d |-- rc0.d |-- rc1.d |-- rc2.d |-- rc3.d (S90myservices -> ../init.d/myservices) |-- rc4.d (S90myservices -> ../init.d/myservices) |-- rc5.d (S90myservices -> ../init.d/myservices) `-- rc6.d

S-ar putea să vă placă și