9i unix startup / shutdown with listener password

Thanks to Laurent Schneider for tips on how to handle listener passwords in scripts. [Update 12-Jan-2007 - ammended script following Laurent's comment, and update 09-Feb-2007 - ammended script following Kevin's comment]

A system startup/shutdown shell script I just used that copes with listener passwords is below.

The location of the listener.ora file was /etc in my case, but that can be different in other servers. The script assumes oracle environment variables are all set correctly at login (the “su -“). This is 9i specific – as explained on Laurent Schneider’s blog post, things are different/better with 10g. Also is only designed to work with a single listener with the default name, LISTENER).

For this script to actually run at system startup/shutdown time, it needs to be linked into the /etc/rc*.d directories, at least /etc/rc3.d (the default startup/shutdown level) although I put it in the others also. The easiest way to do this is using the “chkconfig –add oracle” utility, but it can also be done manually as root user:

vi /etc/init.d/oracle
[pasted in below shell script]
chmod 755 /etc/init.d/oracle
cd /etc/rc1.d
ln -s ../init.d/oracle K99oracle
ln -s ../init.d/oracle S99oracle
cd /etc/rc2.d
ln -s ../init.d/oracle K99oracle
ln -s ../init.d/oracle S99oracle
cd /etc/rc3.d
ln -s ../init.d/oracle K99oracle
ln -s ../init.d/oracle S99oracle
cd /etc/rc4.d
ln -s ../init.d/oracle K99oracle
ln -s ../init.d/oracle S99oracle
cd /etc/rc5.d
ln -s ../init.d/oracle K99oracle
ln -s ../init.d/oracle S99oracle
cd /etc/rc6.d
ln -s ../init.d/oracle K99oracle
ln -s ../init.d/oracle S99oracle


The script Itself:

#!/bin/sh
#
#Start/Stop script for oracle
#

case "$1" in

'start')
su - oracle <<END_SU

#start databases
dbstart

#start oracle listener
lsnrctl start

END_SU
;;

'stop')

#stop oracle 9i listener with password control
ENCRYPTED_PASSWORD=`grep -i password /etc/listener.ora | awk -F= '{print $2}' -`

su - oracle <<END_SU

lsnrctl <<END_LISTENER
set password $ENCRYPTED_PASSWORD
stop
quit
END_LISTENER

#cleanly shutdown immediate databases
dbshut

END_SU
;;
*)
echo "Usage: $0 { start | stop }"
;;
esac
exit 0
This entry was posted in Installs, Scripts, SQL*Net. Bookmark the permalink.

8 Responses to 9i unix startup / shutdown with listener password

  1. note that you never need a password to start a listener 8)
    take care if you have more than one listener

  2. Thanks again. Had I known password wasn’t needed for startup, I might have been tempted to be lazy and skip the listener shutdown step, since I’m a lot less bothered about a listener not being cleanly shutdown than a database.

  3. Kevin says:

    I’m following these steps exactly, but seeing that my script is not able to set variables within the “su – ” routine.

    This is happening both on my RHES Linux 4.0 and hpux 11.11 servers.

    If I put all the oracle commands in a separate script, then everything is fine, but I’m wondering if anyone knows why the example above wouldn’t work for me?

    cheers,
    Kevin

  4. Not sure why that happens, but I just replicated it on a solaris test machine. Fix I used there was to take the environment variable line:

    ENCRYPTED_PASSWORD=`grep -i password /etc/listener.ora | awk -F= ‘{print $2}’ -`

    to be before the su.

    I’ve updated the original post to have that fix in.

  5. Kevin says:

    Ahh, that did it Andrew. Thanks so much

  6. Uneniosits says:

    Thanks for the post

  7. SJ says:

    How does the ‘start’ or ‘stop’ command get passed to the oracle script?

  8. The ‘start’ or ‘stop’ is passed to the script as the first parameter, ‘$1′.

    So from the command line you would type e.g.: “/etc/init.d/oracle start” or use it’s alias: “service oracle start”

    And the good thing is that server shutdowns and startups automatically pass in either ‘start’ or ‘stop’ to the scripts in /etc/init.d.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>