6 Replies Latest reply: Aug 13, 2012 4:52 PM by Catch-22 RSS

    Automatically starting Oracle Enterprise Manager with chkconfig

    RichS
      Folks,

      While Oracle Linux 6 is out (6.2 actually), Oracle has yet to get everything 'working out of the box' with 6.2. Right now (June 2012) you've got to download patches from Oracle, the new way to start services in Linux 6, upstart, doesn't work with all Oracle features yet, etc. Update: You can still use chkconfig with OL6.

      Because of the above, I've been using Oracle Linux 5.8. Linux 5 uses something called chkconfig to register services. You first need to put a script in the right directory: /etc/rc.d/init.d. Linux looks in this directory for scripts and runs those scripts with either a start or stop after them depending on if the system is coming up or going down. Technically this happens every time you change your runlevel (google Unix runlevels for more info), not just when the system goes up or down.

      Here's a script that you can put in /etc/rc.d/init.d. I named mine oracleEM:

      [root@localhost ~]# cd /etc/rc.d/init.d
      [root@localhost init.d]# vi oracleEM

      Enter i to enter insert mode and then enter the below (or just copy and paste it)

      *#!/bin/sh*

      *#chkconfig: 2345 80 05*
      *#description: Oracle Enterprise Manager*

      ORA_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
      ORA_OWNER=oracle
      ORA_SID=orcl

      *# We're checking to see if ps returns 1 or 2 results for pmon_orcl*
      *# If there are two, Oracle is running, one we are just seeing our grep*
      ORACLE_STATUS=$(ps -eaf | grep pmon_$ORA_SID | wc -l)

      *if [ ! -f $ORA_HOME/bin/emctl ]*
      then
      echo "Enterprise Manager startup: cannot start"
      exit
      fi

      case "$1" in
      *"start")*
      *if [ $ORACLE_STATUS -lt 2 ]*
      then
      echo "Waiting for Oracle instance $ORA_SID to start before starting Enterprise Manager"
      fi
      *while [ $ORACLE_STATUS -lt 2  ];do*
      echo "Waiting...."
      sleep 5
      ORACLE_STATUS=$(ps -eaf | grep pmon_$ORA_SID | wc -l)
      done

      su - $ORA_OWNER -c "$ORA_HOME/bin/emctl start dbconsole"
      *;;*
      *"stop")*
      su - $ORA_OWNER -c "$ORA_HOME/bin/emctl stop dbconsole"
      *;;*
      esac

      Press the Esc key to leave insert mode, then type *:wq* to write the file and quit.

      We'll need to make the script executable, so we need to run the following command:

      [root@localhost init.d]# *chmod +x oracleEM*

      Finally we need to register the oracleEM script with Linux using the chkconfig command:

      [root@localhost init.d]# *chkconfig --add oracleEM*

      Now Enterprise Manager will start up automatically when you start your system, but only after Oracle has started.

      Rich

      Edited by: RichS on Jun 9, 2012 1:00 AM
        • 1. Re: Automatically starting Oracle Enterprise Manager with chkconfig
          Avi Miller-Oracle
          RichS wrote:
          While Oracle Linux 6 is out (6.2 actually), Oracle has yet to get everything 'working out of the box' with 6.2. Right now (June 2012) you've got to download patches from Oracle, the new way to start services in Linux 6, upstart, doesn't work with all Oracle features yet, etc.
          While Oracle Linux 6.2 now uses upstart, the chkconfig mechanism still works for legacy scripts. You can use a mixture of both legacy SysV init scripts and upstart scripts. In fact, there are a bunch of things in OL6 that still use legacy SysV init scripts, Apache being an easy example.
          Because of the above, I've been using Oracle Linux 5.8, the terminal release of the Oracle Linux 5 line.
          Also, Oracle Linux 5.8 is not the terminal release of the Oracle Linux 5 line: I expect there will be at least another release (5.9) as both Red Hat and Oracle have extended the production lifecycle to 10 years. The end of the production lifecycle for RHEL5 (and thus Oracle Linux 5) is March 2017.
          • 2. Re: Automatically starting Oracle Enterprise Manager with chkconfig
            RichS
            Thanks Avi. I've updated the original post.

            Rich
            • 3. Re: Automatically starting Oracle Enterprise Manager with chkconfig
              RichS
              As I sat around thinking about this, I realized that there is a side effect of the script.

              If, for some reason, your database doesn't come up when you boot your machine, the machine will perpetually loop waiting for the database to come up before it starts enterprise manager. You could modify the script to put in a time limit on the wait if that concerns you.
              • 4. Re: Automatically starting Oracle Enterprise Manager with chkconfig
                RichS
                Below is the script that will only wait so long...

                #!/bin/sh

                #chkconfig: 2345 80 05
                #description: Oracle Enterprise Manager

                ORA_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
                ORA_OWNER=oracle
                ORA_SID=orcl
                COUNT=0

                # We're checking to see if ps returns 1 or 2 results for pmon_orcl
                # If there are two, Oracle is running, one we are just seeing our grep
                ORACLE_STATUS=$(ps -eaf | grep pmon_$ORA_SID | wc -l)

                if [ ! -f $ORA_HOME/bin/emctl ]
                then
                echo "Enterprise Manager startup: cannot start"
                exit
                fi

                case "$1" in
                "start")
                if [ $ORACLE_STATUS -lt 2 ]
                then
                echo "Waiting for Oracle instance $ORA_SID to start before starting Enterprise Manager"
                fi
                while [ $ORACLE_STATUS -lt 2  ];do
                echo "Waiting...."
                sleep 5
                ORACLE_STATUS=$(ps -eaf | grep pmon_$ORA_SID | wc -l)
                COUNT=`expr $COUNT + 1`
                if [ $COUNT -gt 5 ]
                then
                exit
                fi
                done

                su - $ORA_OWNER -c "$ORA_HOME/bin/emctl start dbconsole"
                ;;
                "stop")
                su - $ORA_OWNER -c "$ORA_HOME/bin/emctl stop dbconsole"
                ;;
                esac
                • 5. Re: Automatically starting Oracle Enterprise Manager with chkconfig
                  RichS
                  So this doesn't work...

                  Even if I change the #chkconfig: 2345 80 05 line to #chkconfig: 5 99 05 Oracle Enterprise Manager isn't started when the machine is up. Obviously Oracle isn't up and running when the script starts. Any idea on how I could get this to work so my students don't have to type emctl start dbconsole after the machine has booted?

                  Thanks,

                  Rich
                  • 6. Re: Automatically starting Oracle Enterprise Manager with chkconfig
                    Catch-22
                    The script you are using will not work for RHEL or Oracle Linux since it is incorrect and missing important coding.

                    You can probably fix the script by removing the dash (-) from the su command and adding the lockfile that is required for RHEL to process the stop routine at system shutdown. The dash will reset the shell environment and the startup won't work. You should also start it in the background in order not to prolong the system startup more then necessary.
                    lockfile=/var/lock/subsys/oracleEM
                    ...
                    start) 
                       su $ORA_OWNER -c "$ORA_HOME/bin/emctl start dbconsole &" &>/dev/null
                       touch $lockfile
                       ;;
                    stop)
                       su $ORA_OWNER -c "$ORA_HOME/bin/emctl stop dbconsole"
                       rm -rf $lockfile
                       ;;
                    ...
                    You do not need to start your Oracle instance before starting dbconsole. So there is no need for the "sleep" routine. You can start the Oracle Database control console even when the instance is down:

                    For instance:

                    <pre>
                    [oracle@vm005 ~]$ ps -ef | grep pmon
                    oracle 17749 10343 0 22:48 pts/3 00:00:00 grep pmon

                    $ emctl start dbconsole
                    Oracle Enterprise Manager 11g Database Control Release 11.2.0.1.0
                    Copyright (c) 1996, 2009 Oracle Corporation. All rights reserved.
                    https://vm005.example.com:1158/em/console/aboutApplication
                    Starting Oracle Enterprise Manager 11g Database Control ....... started.
                    </pre>