Operating System - HP-UX
1752603 Members
4702 Online
108788 Solutions
New Discussion юеВ

Re: Putting the Oracle Listener in a rc3.d script

 
SOLVED
Go to solution
Rob_Taylor
Advisor

Putting the Oracle Listener in a rc3.d script

Hi,

I am trying to automate the start of the ORacle 10g listener in a script at run level 3. The stop script works just fine but the start does not seem to execute properly.

Any ideas folks?

Here is the entire script:
PATH=/usr/sbin:/usr/bin:/sbin
export PATH

# NOTE: If your script executes in run state 0 or state 1, then /usr might
# not be available. Do not attempt to access commands or files in
# /usr unless your script executes in run state 2 or greater. Other
# file systems typically not mounted until run state 2 include /var
# and /opt.

rval=0

# Check the exit value of a command run by this script. If non-zero, the
# exit code is echoed to the log file and the return value of this script
# is set to indicate failure.

set_return() {
x=$?
if [ $x -ne 0 ]; then
echo "EXIT CODE: $x"
rval=1 # script FAILed
fi
}

case $1 in
'start_msg')
# Emit a _short_ message relating to running this script with
# the "start" argument; this message appears as part of the checklist.
echo "Starting the Oracle 10g Agent - no start executed"
;;

'stop_msg')
# Emit a _short_ message relating to running this script with
# the "stop" argument; this message appears as part of the checklist.
echo "Stopping the Oracle 10g Agent - no stop executed"
;;

'start')

# Execute the commands to start your subsystem
su oracle -c "/u01/app/oracle/product/10.2.0/agent10g/bin/emctl start agent" > orastart.txt
set_return
;;

'stop')
# Execute the commands to stop your subsystem
su oracle -c "/u01/app/oracle/product/10.2.0/agent10g/bin/emctl stop agent" > orastop.txt
set_return
;;

*)
echo "usage: $0 {start|stop|start_msg|stop_msg}"
rval=1
;;
esac

exit $rval

Robert
6 REPLIES 6
A. Clay Stephenson
Acclaimed Contributor

Re: Putting the Oracle Listener in a rc3.d script

Put your su'ed commands inside a wrapper that sets and exports all ORACLE related environment variables before actually calling any oracle commands.
If it ain't broke, I can fix that.
Court Campbell
Honored Contributor

Re: Putting the Oracle Listener in a rc3.d script

I thought you used lsnrctl to start/stop listeners. emctl is for the enterprise manager.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Rob_Taylor
Advisor

Re: Putting the Oracle Listener in a rc3.d script

Something like this?

su oracle -c "export ORACLE_HOME=/u01/app/oracle/product/10.2.0/agent10g;emctl start agent"
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Putting the Oracle Listener in a rc3.d script

No. Create a shell script which is called by your su command; something like this:

/usr/local/bin/myorastart.sh
-------------------------------------
#!/usr/bin/sh

typeset -i STAT=0
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=${ORACLE_BASE}/product/10.x.y
ORACLE_SID=mickey
TNS_ADMIN=${ORACLE_HOME}/network/admin
PATH=${PATH}:${ORACLE_HOME}/bin
export ORACLE_BASE ORACLE_HOME ORACLE_SID TNS_ADMIN PATH
emctl start agent
STAT=${?}
exit ${STAT}
--------------------------------------------

The start) section of your rc'ed command does the "su oracle -c /usr/local/bin/myorastart.sh".
If it ain't broke, I can fix that.
Rob_Taylor
Advisor

Re: Putting the Oracle Listener in a rc3.d script

That makes sense now. Thanks for your help!

Rob
A. Clay Stephenson
Acclaimed Contributor

Re: Putting the Oracle Listener in a rc3.d script

Oh, I'm sure that you are also going to get some helpful advice about do an su - oracle -c command but I would ignore. The "su - oracle" does indeed source oracle's .profile and will set the environment variable but there is a problem. The default .profiles under HP-UX contain commands like tput, tset, and tabs which expect an interactive environment --- which rc ain't. You have to surround those commands with something like:
if [[ -t 0 ]]
then
stty ...
tabs ...
fi

but the better way is to create a file something like /usr/local/bin/oraenv.sh which sets and exports the variables and then both oracle's .profile and your rc'ed script source this file (via the . (dot) operator). The sourced file must not contain a return or exit statement because that would have the effect of exiting the foreground process since a sourced file does not create a child process.

This means that the above script would be changed to:

#!/usr/bin/sh

typeset -i STAT=0
./usr/local/bin/oraenv.sh
emctl start agent
STAT=${?}
exit ${STAT}
If it ain't broke, I can fix that.