Search This Blog

Friday 24 October 2014

Figuring out Linux start-up from Oracle Developer Days

Few months back I had downloaded the Oracle Developer Days appliance. It had Oracle Linux with Oracle 11g and APEX installed. When I boot the machine Oracle database was already started and running. I wondered – How is it done? The rest of this post explains this "how". 

While preparing for the GSEC exam, I have read that during Linux boot up the first process to be started is the init (initialization). I also know that init is a daemon process and refers to the /etc/inittab file for further instructions. I go and check out the inittab file given below:







# Default runlevel. The runlevels used by RHS are:
#   0 - halt (Do NOT set initdefault to this)

#   1 - Single user mode

#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)

#   3 - Full multiuser mode

#   4 - unused

#   5 - X11

#   6 - reboot (Do NOT set initdefault to this)

#

id:5:initdefault:

 

# System initialization.

si::sysinit:/etc/rc.d/rc.sysinit

 

l0:0:wait:/etc/rc.d/rc 0

l1:1:wait:/etc/rc.d/rc 1

l2:2:wait:/etc/rc.d/rc 2

l3:3:wait:/etc/rc.d/rc 3

l4:4:wait:/etc/rc.d/rc 4

l5:5:wait:/etc/rc.d/rc 5

l6:6:wait:/etc/rc.d/rc 6


From the file I get some more information to proceed further.


  1. There are 7 run levels (0 to 6)


  2. The initdefault keyword specifies the default run level. Here the default run level is  5 (which is “X11” aka the X-Windows System)


  3. The directory for the run level is /etc/rc.d/ Well, here is where I should go next!






A listing on the /etc/rc.d directory gives me the following output: 







[root@localhost rc.d]# ls -ralt
total 124

-rwxr-xr-x  1 root root   220 Jul  4  2009 rc.local

-rwxr-xr-x  1 root root  2255 Jul  4  2009 rc

-rwxr-xr-x  1 root root 27752 Mar  3  2010 rc.sysinit

drwxr-xr-x 10 root root  4096 Apr 15  2010 .

drwxr-xr-x  2 root root  4096 Aug 22  2012 rc6.d

drwxr-xr-x  2 root root  4096 Aug 22  2012 rc5.d

drwxr-xr-x  2 root root  4096 Aug 22  2012 rc4.d

drwxr-xr-x  2 root root  4096 Aug 22  2012 rc3.d

drwxr-xr-x  2 root root  4096 Aug 22  2012 rc2.d

drwxr-xr-x  2 root root  4096 Aug 22  2012 rc1.d

drwxr-xr-x  2 root root  4096 Aug 22  2012 rc0.d

drwxr-xr-x  2 root root  4096 Aug 20 21:29 init.d

drwxr-xr-x 97 root root 12288 Aug 20 21:32 ..


From the above output it looks like there are separate directories for each run level. However, I am interested only in exploring run level 5 and that too processes named oracle (remember, the original question was "how does Oracle database start automatically at the time of system boot?". So I navigate to the /etc/rc.d/rc5.d and search for “oracle” :







[root@localhost rc5.d]# ls -ralt | grep -i ora
lrwxrwxrwx  1 root root   18 Apr  6  2010 S99oracle -> /etc/init.d/oracle


Before continuing the chase, let me mention something about this name "S99oracle". The S indicates that the file is a start script. When Linux boots up, the S* scripts in the default run level directory are executed with the argument "start". The 99 indicates the priority of the script (1 being the highest priority or first to be executed). And of course "oracle" indicates the script could have something to do with starting up the Oracle database. With this understanding in mind, I open the S99oracle file:







#!/bin/sh
#

#

export JAVA_HOME=/usr/java/latest

export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_2

export ORACLE_HOME_LISTENER=$ORACLE_HOME

export ORACLE_TRACE=Y

export PATH=$JAVA_HOME/bin:$ORACLE_HOME/bin:$PATH

echo $PATH

 

# Source function library.

. /etc/rc.d/init.d/functions

 

# See how we were called.

case "$1" in

  start)

        su - oracle -c "$ORACLE_HOME/bin/lsnrctl start"

        su - oracle -c $ORACLE_HOME/bin/dbstart

        su - oracle -c "/home/oracle/apexlistener.sh start"

        ;;

  stop)

        su - oracle -c $ORACLE_HOME/bin/dbshut

        su - oracle -c "$ORACLE_HOME/bin/lsnrctl stop"

        su - oracle -c "/home/oracle/apexlistener.sh stop"

        ;;

  restart|reload)

        su - oracle -c $ORACLE_HOME/bin/dbshut

        su - oracle -c "$ORACLE_HOME/bin/lsnrctl stop"

        su - oracle -c "/home/oracle/apexlistener.sh stop"

        su - oracle -c "$ORACLE_HOME/bin/lsnrctl start"

        su - oracle -c $ORACLE_HOME/bin/dbstart

        su - oracle -c "/home/oracle/apexlistener.sh start"

        ;;

  status)

        $ORACLE_HOME/bin/lsnrctl status

        ;;

  *)

        echo $"Usage: $0 {start|stop|restart|reload}"

        exit 1

esac

 

exit 0


As expected the S99oracle file contains 3 other scripts that get called - lsnrctl (to start the database listener), dbstart (don't know what this is, will have to check), apexlistener.sh (to start the Apex DB Listener). Now moving on to the dbstart file... 







#!/bin/sh
#

# $Id: dbstart.sh 22-may-2008.05:05:45 arogers Exp $

# Copyright (c) 1991, 2008, Oracle. All rights reserved. 

#

 

###################################

#

# usage: dbstart $ORACLE_HOME

#

# This script is used to start ORACLE from /etc/rc(.local).

# It should ONLY be executed as part of the system boot procedure.

#

# This script will start all databases listed in the oratab file

# whose third field is a "Y".   If the third field is set to "Y" and

# there is no ORACLE_SID for an entry (the first field is a *),

# then this script will ignore that entry.

#

# This script requires that ASM ORACLE_SID's start with a +, and

# that non-ASM instance ORACLE_SID's do not start with a +.


"This script will start all databases listed in the oratab file" - Hmm.... At this point I have understood how the Oracle database gets started automatically when Linux boots up. But just for completeness' sake. I shall take a look at the oratab file and get off this file chain... 







[oracle@localhost /]$ find . -name "*oratab*" 2>/dev/null
./home/oracle/app/oracle/product/11.2.0/dbhome_2/install/oratab

./etc/oratab


There are two versions, which one does Oracle DB use? I did a diff to find out if the content of the files was different:







 [oracle@localhost bin]$ diff /etc/oratab /home/oracle/app/oracle/product/11.2.0/dbhome_2/install/oratab
1,20d0

< #

< # 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.

< #

< #

< orcl:/home/oracle/app/oracle/product/11.2.0/dbhome_2:Y


The file /home/oracle/app/oracle/product/11.2.0/dbhome_2/install/oratab is a ZERO byte file. All the entries are present in the /etc/oratab file only.


Before ending this article, let me summarize some important points about /etc/oratab file:


  1. It’s used by ORACLE utilities

  2. It is created by root.sh

  3. It is Updated by DBCA when creating a database. Important: If you create a database through CREATE DATABASE command then the /etc/oratab DOES NOT get updated

  4. The records in the file should be in the format $ORACLE_SID:$ORACLE_HOME:<N|Y>:


 

No comments:

Post a Comment