Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Script to start/stop Oracle 9i
"BAD8888" <bad8888l_at_nowhere.com> wrote in message
news:2n6l4kFsq1b9U1_at_uni-berlin.de...
> How can I write a script to start/stop Oracle 9i on Redhat Linux 3.0
> Advanced server. Any examples or helpful links would be great.
>
> thanx.
Oracle already supplies the necessary scripts to automate startup and shutdown. They're called dbstart and dbshut, and can be found in ORACLE_HOME/bin. All you need do is know how to call those scripts appropriately from the assorted init scripts that Red Hat uses to automate startup and shutdown of assorted other processes. Also, be aware that they work by interrogating the file /etc/oratab for details of which instances to startup/shutdown automatically, so that needs setting appropriately, too.
So, with an /etc/oratab set to something like this:
*:/u01/app/oracle/9i:N
lx92:/u01/app/oracle/9i:Y
OEMREP:/u01/app/oracle/9i:Y
I can then create a new shell script /etc/init.d/dbora, like so:
#!/bin/sh #Startup script for Oracle databases #Set the environment variables for the invoker of the dbstart/dbshut scripts
. /home/oracle/.bashrc
start() {
su – oracle -c $ORACLE_HOME/bin/dbstart
touch /var/lock/subsys/dbora
}
stop() {
su – oracle -c $ORACLE_HOME/bin/dbshut
rm -f /var/local/subsys/dbora
}
case “$1” in
start) start ;; stop) stop ;; *) exit 1
This script in turn calls the dbstart or dbshut scripts that Oracle supplies, and they in turn inspect the oratab file to work out what to start or shut. You then need simply to link this script into the assorted run-level directories that Red Hat uses. I go over the top when doing so, and issue this little lot:
ln -s /etc/init.d/dbora /etc/rc.d/rc0.d/K10dbora ln -s /etc/init.d/dbora /etc/rc.d/rc1.d/K10dbora ln -s /etc/init.d/dbora /etc/rc.d/rc2.d/K10dbora ln -s /etc/init.d/dbora /etc/rc.d/rc3.d/S90dbora ln -s /etc/init.d/dbora /etc/rc.d/rc4.d/S90dbora ln -s /etc/init.d/dbora /etc/rc.d/rc5.d/S90dbora ln -s /etc/init.d/dbora /etc/rc.d/rc6.d/K10dbora
Linux purists will blanch when they see that and complain loudly that it indicates I don't know what I'm doing, which is probably true, but at least it works.
Then make sure the dbora script is actually executable:
chmod 755 /etc/init.d/dbora
And then test it out by invoking your dbora script manually (ie, type "./etc/init.d/dbora"). It may fail because dbstart and dbshut don't understand the concept of an spfile, so if you're using one of those and no equivalent init.ora exists, then the scripts complain that they can't find a suitable init.ora. If that happens for you, simply create an initXXX.ora in ORACLE_HOME/dbs (where XXX is your ORACLE_SID) and have the new file contain one line: spfile=/blah/wherever/spfileXXX.ora. Then dbstart and dbshut can find a suitable init.ora that tells them how to actually find the spfile. You'll need to do that for every instance/database mentioned in the oratab file, of course.
For further refinement, you will want to get the listener and intelligent agent into the dbora script (dbstart and dbshut only deal with instances). So your final dbora script may well end up looking more like this:
#!/bin/sh #Startup script for Oracle databases #Set the environment variables for the invoker of the dbstart/dbshut scripts. /home/oracle/.bashrc
start() {
su – oracle -c “lsnrctl start” su – oracle -c “agentctl start” su – oracle -c “oemctl start oms” su – oracle -c $ORACLE_HOME/bin/dbstart touch /var/lock/subsys/dbora
su – oracle -c “lsnrctl stop” su – oracle -c “agentctl stop” su – oracle -c “oemctl stop oms sysman/password” su – oracle -c $ORACLE_HOME/bin/dbshut rm -f /var/local/subsys/dbora } case “$1” in start) start ;; stop) stop ;; *) exit 1
And finally, you may want to edit the dbshut script, and locate the various references to the "shutdown" command, and replace them with, for example, "shutdown immediate"... otherwise it can become a marathon just trying to shut your RH box down because the script as supplied does a very polite shutdown normal, which means that one user logged on prevents the shutdown of the Oracle instance from ever happening, and the script doesn't therefore ever get to finish -and hence the Linux shutdown process can't complete either.
Regards
HJR
Received on Mon Aug 02 2004 - 06:53:36 CDT