Skip to Main Content

Infrastructure Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Automatically starting Oracle Enterprise Manager with chkconfig

RichSJun 8 2012 — edited Aug 13 2012
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 10 2012
Added on Jun 8 2012
6 comments
3,415 views