Friday 11 December 2009

Grid Control components be automatically started and stopped upon host shutdown or reboot on Red Hat/Oracle Enterprise Linux

How can the Grid Control components be automatically started and stopped upon host shutdown or reboot on Red Hat/Oracle Enterprise Linux?


Applies to:

Enterprise Manager Grid Control - Version: 10.2.0.1 to 10.2.0.4
Linux x86

Goal

How can the Grid Control components be automatically started and stopped upon host shutdown or reboot on Red Hat/Oracle Enterprise Linux?

Solution

I. Automatically Starting Grid Control components on Red Hat/Oracle Enterprise Linux

Grid Control provides several scripts that allow for automatic starting of its components during
the boot process. The specific scripts for each component are located on its ORACLE_HOME. On a normal Grid Control installation the scripts controlling the automatic startup/shutdown are

$DB_HOME/install/unix/scripts/seedstup
$OMS_HOME/install/unix/scripts/agentstup
$AGENT_HOME/install/unix/scripts/agentstup

There is also a general startup script that will be run by the Linux boot up process. The script called gcstarup is located on
/etc/rc.d/init.d/gcstartup,
and to be called at startup two links are created to it
/etc/rc.d/rc3.d/S99gcstartup
/etc/rc.d/rc5.d/S99gcstartup


By default, this functionality should be activated after installation, however, sometimes there is some misconfiguration that prevents Grid Control components to start automatically on boot time. To check that the configuration is correct, follow the steps below.

1.- Database script.
1.1 If Grid Control has been installed with the new database option, the startup/shutdown script for the database should be located on the following location

$DB_HOME/install/unix/scripts/seedstup.

Check the following lines and ensure that the correct values are present

export ORACLE_HOME=<ORACLE_HOME_PATH>
user=<OS_user_that_owns_the_installation>
export ORACLE_SID=<SID>

1.2 If Grid Control was installed using an existing database, the startup script will not exist on the previous mentioned location. To construct the database startup script follow the below steps
1.2.1.- Create the directory scripts
$mkdir $ORACLE_HOME/install/unix/scripts
1.2.2.- Create the file seedstup
$touch $ORACLE_HOME/install/unix/scripts/seedstup
1.2.3.- Open the file seedstup and enter the following text. Replace the environment variables and the user with the appropriate values.

#!/bin/sh
#Script to start and stop the Listener and Database during shutdown and restart of the machine

function dbop
{
todo=$1
case $todo in

startup)
$ORACLE_HOME/bin/lsnrctl start
$ORACLE_HOME/bin/sqlplus '/as sysdba'<<- _START_DB
startup;
exit;
_START_DB
;;

shutdown)

$ORACLE_HOME/bin/lsnrctl stop;
$ORACLE_HOME/bin/sqlplus '/as sysdba'<<- _STOP_DB
shutdown immediate;
exit;
_STOP_DB
;;

*)
echo $"Usage: $0 {start|stop}";
exit 1;
esac

}

export ORACLE_HOME=<ORACLE_HOME_PATH>
user=<OS_user_that_owns_the_installation>
export ORACLE_SID=<SID>
SU=/bin/su

if [ $# -gt 1 ]; then
dbop $2
export -n ORACLE_HOME
export -n ORACLE_SID
exit
fi

case "$1" in
start)
$SU $user -c "$ORACLE_HOME/install/unix/scripts/seedstup $1 startup"
;;
stop)
$SU $user -c "$ORACLE_HOME/install/unix/scripts/seedstup $1 shutdown"
;;
*)
echo $"Usage: $0 {start|stop}";
exit 1;
esac

export -n ORACLE_HOME
export -n ORACLE_SID



$chmod +x seedstup
B.- Checking the oms and agent startup scripts
B.1 Open the file
$OMS_ORACLE_HOME/install/unix/scripts/omsstup
and check that the ORACLE_HOME and user are correctly set
B.2 Open the file

$AGENT_HOME/install/unix/scripts/agentstup
and check that the ORACLE_HOME and user are correctly set

C.- Configure the gcstartup script
Grid Control installation installs the gcstartup script and the appropriate links to it to process it on the preferred runlevel. The locations are
/etc/rc.d/init.d/gcstartup
/etc/rc.d/rc5.d/S99gcstartup
/etc//rc.d/rc3.d/S99gcstartup

The two files on the bottom should be hard links to the first script.
On each new installation or modification of the Grid Control components, lines are added to gcstartup which may cause malfunctioning of the script. For the script to work properly, edit the script following the steps below.

C.1. Please backup the three files mentioned above. Then edit the gcstartup script to contain only the
following text:

#!/bin/sh
#Source Function Library

if [ -f /etc/init.d/functions ]
then
. /etc/init.d/functions
else
if [ -f /etc/rc.d/init.d/functions ]
then
. /etc/rc.d/init.d/functions
fi
fi


if [ -f <DB_HOME>/install/unix/scripts/seedstup ]; then
. <DB_HOME>/install/unix/scripts/seedstup
fi


if [ -f <OMS_HOME>/install/unix/scripts/omsstup ]; then
. <OMS_HOME>/install/unix/scripts/omsstup
fi


if [ -f <AGENT_HOME>/install/unix/scripts/agentstup ]; then
. <AGENT_HOME>/install/unix/scripts/agentstup
fi


Replace <AGENT_HOME>, <DB_HOME> and <OMS_HOME> with the complete path to each home.

D.- Testing the script
Shutdown all Grid Control components
execute the command
/etc/rc.d/init.d/gcstartup start

All components should start in the correct order

II. Automatically Stopping Grid Control components

To stop the Grid Control Components automatically upon host shutdown or reboot, please follow the
next steps. It is assumed that you have already applied the above steps to ensure automatic
startup of the components.

1.- Open the gcstartup script, located on
/etc/rc.d/init.d/gcstartup

2.- Edit the script replacing its contents by the following text.

#!/bin/sh
#Source Function Library

if [ -f /etc/init.d/functions ]
then
. /etc/init.d/functions
else
if [ -f /etc/rc.d/init.d/functions ]
then
. /etc/rc.d/init.d/functions
fi
fi

case "$1" in
start)

if [ -f <DB_HOME>/install/unix/scripts/seedstup ]; then
. <DB_HOME>/install/unix/scripts/seedstup
fi


if [ -f <OMS_HOME>/install/unix/scripts/omsstup ]; then
. <OMS_HOME>/install/unix/scripts/omsstup
fi


if [ -f <AGENT_HOME>/install/unix/scripts/agentstup ]; then
. <AGENT_HOME>/install/unix/scripts/agentstup
fi

touch /var/lock/subsys/gcstartup
;;
stop)


if [ -f <OMS_HOME>/install/unix/scripts/omsstup ]; then
. <OMS_HOME>/install/unix/scripts/omsstup
fi


if [ -f <AGENT_HOME>/install/unix/scripts/agentstup ]; then
. <AGENT_HOME>/install/unix/scripts/agentstup
fi

if [ -f <DB_HOME>/install/unix/scripts/seedstup ]; then
. <DB_HOME>/install/unix/scripts/seedstup
fi
rm -f /var/lock/subsys/gcstartup

esac


Replace <AGENT_HOME>, <DB_HOME> and <OMS_HOME> with the complete path to each home.

This modification ensures that the same gcstartup script can be used to start and stop the components in the right order. Furthermore, in order to shutdown services, Red Hat Linux requires that each service creates a file under the /var/log/subsys/ directory to notify the system that the service is active. The above script
creates that file on startup and removes it when stopping the components.
Only the first time you shutdown or reboot it will be necessary to
create that file manually, using the following command
$touch /var/lock/subsys/gcstartup

4.- Create the following symbolic links to include the gcstartup script on the shutdown and reboot
process

$ln -s /etc/rc.d/init.d/gcstartup /etc/rc.d/rc0.d/K01gcstartup
$ln -s /etc/rc.d/init.d/gcstartup /etc/rc.d/rc6.d/K01gcstartup

# ln -s /etc/init.d/gcstartup /etc/rc5.d/S98gcstartup
# ln -s /etc/init.d/gcstartup /etc/rc3.d/S98gcstartup


The K on the symbolic link indicates it is a Kill script and the 01 indicates its priority on the
shutdown process.

5.- Testing the script
Execute the commands
/etc/rc.d/init.d/gcstartup start
/etc/rc.d/init.d/gcstartup stop

The components should start and stop automatically on the correct order.

References

BUG:5383799 - OMS,AGENT AND REPOSITORY DATABASE DO NOT AUTO START ON REBOOT OF MACHINE
NOTE:392426.1 - Problem: gcstartup does not start Agent and Management Server during server reboot




1 comment:

Unknown said...

Thank you for this, it was very helpful.