OraMatt: YABAOracle

Yet Another Blog About Oracle

init Script for OEM & Ops Center

I hate starting stuff up manually…so I wrote this…

Enjoy

——————————————————————————


#!/bin/bash
#
# init script for starting, stoping, restarting OEM & Ops Center
#
# Author: MattD
# Created: 01.25.2013
#
#

# Install instructions
# 
# Place in /etc/init.d
# chgrp dba oemora
# chmod 750 oemora
# ln -s /etc/init.d/oemora /etc/rc0.d/K01oemora
# ln -s /etc/init.d/oemora /etc/rc3.d/S99oemora



# Set Environment
# Change based on site
export DB_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export OEM_HOME=/u01/app/oracle/product/OEMHome/oms
export OPSCENTER_HOME=/opt/SUNWxvmoc
export ORA_OWNER=oracle


#export ECStatus=`sudo $OPSCENTER_HOME/bin/ecadm status`
#export ProxyStatus=`sudo $OPSCENTER_HOME/bin/proxyadm status`
#export OEMStatus=`su  $ORA_OWNER -c "$OEM_HOME/bin/emctl status oms" | grep Oracle | grep Down | awk '{print $5}'`



# Set the SID for the OEM/Ops Center Database
export ORACLE_SID=oem

export PATH=${PATH}:$ORACLE_HOME/bin

# Functions
function start_it()
	{
	echo "Starting Management Stack"
		echo "."
		# Start the lisenter
		export ORACLE_HOME=$DB_HOME
		su $ORA_OWNER -c "$ORACLE_HOME/bin/lsnrctl start"
		# Start the database
		export ORACLE_HOME=$DB_HOME
		export ORACLE_SID=$ORACLE_SID
		su $ORA_OWNER -c "$ORACLE_HOME/bin/sqlplus / as sysdba <<EOF  
		startup
		exit;
		EOF
		"
		# Start Ops Center
		su $ORA_OWNER -c "sudo $OPSCENTER_HOME/bin/ecadm start -vw &"
		su $ORA_OWNER -c "sudo $OPSCENTER_HOME/bin/proxyadm start -vw &"
		# Start OEM
		su $ORA_OWNER -c "ulimit -n 4096;$OEM_HOME/bin/emctl start oms &" 	
	}

function stop_it()
	{
	echo "Stopping Management Stack"
		echo "."
		# Stop Ops Center
		su $ORA_OWNER -c "sudo $OPSCENTER_HOME/bin/ecadm stop -vw &"
		su $ORA_OWNER -c "sudo $OPSCENTER_HOME/bin/proxyadm stop -vw &"
		# Stop OEM
		su $ORA_OWNER -c "ulimit -n 4096;$OEM_HOME/bin/emctl stop oms -force -all  "
		# Stop the database
		export ORACLE_HOME=$DB_HOME
		export ORACLE_SID=$ORACLE_SID
		su $ORA_OWNER -c "$ORACLE_HOME/bin/sqlplus / as sysdba <<EOF  
		shutdown immediate
		exit;
		EOF
		"
		# Stop the lisenter
		export ORACLE_HOME=$DB_HOME
		su $ORA_OWNER -c "$ORACLE_HOME/bin/lsnrctl stop"
	}


case "$1" in
	start)
		start_it
	;;
	stop)
		stop_it
	;;
	restart)
		echo "Restarting Management Stack"
		echo "."
		stop_it
		start_it
	;;
	*)
		echo "Usage: /etc/init.d/oemora start|stop|restart"
		exit 1
	;;
esac

Leave a comment

Navigation

About

I’m Matt and I do Oracle things.