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. That is, 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
Thursday 11 January 2007 at 6:41 pm
note that you never need a password to start a listener 8)
take care if you have more than one listener
Friday 12 January 2007 at 4:02 pm
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.
Friday 9 February 2007 at 8:31 am
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
Friday 9 February 2007 at 4:44 pm
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.
Monday 12 February 2007 at 11:47 am
Ahh, that did it Andrew. Thanks so much