28 September 2007

Automate Startup/Shutdown of Oracle Products on SLES 10.0

Previous Posts:
Oracle 10g Rel 2 on SLES 10.0
Installation Prepation
Hardware and Software check
Software Installation
Patch Oracle Database Software
Create Database
Install Oracle HTTP Server
Install APEX
Install BI Publisher
Next Posts:
Install Oracle Workflow

Automated Startup and Shutdown of installed Oracle products will be implemented using shell script "dbora". This script is based on description that You can find in Oracle Metalink.

First check that the file /etc/oratab contains entry for the Database that You like to Start/shut:
vl094:~ # cat /etc/oratab
DB094:/appl/oracle/product/10.2.0/db_1:Y


For the Start/Shut for the Database and the Listener I will use scripts distributed with Oracle DB Software located in $ORACLE_HOME/bin:
dbstart $ORACLE_HOME - to start the database and listener and
dbshut $ORACLE_HOME - to stop the database and listener. You must remember that this two scripts requires one parameter, this parameter is ORACLE_HOME.

You must save the Script in /etc/init.d.
Set scripts permissions:
vl094:~ # cd /etc/init.d/
vl094:/etc/init.d # chmod 755 dbora

Register Service:
vl094:/etc/init.d # /sbin/chkconfig --add dbora
dbora 0:off 1:off 2:off 3:on 4:off 5:on 6:off


"chkconfig" will create symbolic links under rc3.d and rc5.d to /etc/init.d/dbora.

SLES "insserv" utility (used from "chkconfig") uses the following header to define run level and start/shut order:
     6  ### BEGIN INIT INFO
7 # Provides: dbora
8 # Required-Start: $local_fs $remot_fs $netdeamons
9 # Required-Stop:
10 # Default-Start: 3 5
11 # Default-Stop: 0 1 2 3 4 5 6
12 # Description: start/shutdown of Database and other Oracle Products
13 ### END INIT INFO
Script to start BI Publisher is not running in background after the start. So I started the BI Publisher Script with "nohup" and in background with "&".
After the start I simply wait for 60 seconds, and then continue with the next step. Naturally, there is better methods to check if the process is started, but for me it works perfectly.
    46      # oracle bi publisher
47 echo "Starting BI Publisher..."
48 su - $OBIP_USER -c "nohup $OBIP_HOME/oc4j_bi/bin/oc4j -start
>>$OBIP_HOME/startbip.log &"

49 RET_BIP=$?
50 echo "Sleeping 60 sec..."
51 sleep 60

I noticed that the Oracle HTTP Server processes need sometimes about a minute to startup - so I am "sleeping"for 60 seconds after start of Oracle HTTP Server. Not so elegant - but in my style.
    55      # oracle http server
56 su - $OHS_USER -c "$OHS_HOME/opmn/bin/opmnctl startall"
57 RET_HS=$?
58 echo "Sleeping 60 sec..."
59 sleep 60
The "touch" command would create a file at the startup of the database. The Oracle process would now have a lock on the above file which should be released at time of OS reboot. The script which is called by 'inittab' whenever the run level is changed, looks for the existence of a lock file in "/var/lock/subsys". If this lock file does not exist, the stop command will not be issued.
    60      # touch lock file
61 touch /var/lock/subsys/dbora

I added simple logging - log file will be located in /tmp/dbora.log

Here is the complete Script:

vl094:/etc/init.d # cat -n dbora

1 #! /bin/sh
2 #
3 # Author: Flavio, Modified script "dbora"
found on "metalink.oracle.com"

4 # Homepage: OracleByFla.blogspot.com
5 #
6 ### BEGIN INIT INFO
7 # Provides: dbora
8 # Required-Start: $local_fs $remot_fs $netdeamons
9 # Required-Stop:
10 # Default-Start: 3 5
11 # Default-Stop: 0 1 2 3 4 5 6
12 # Description: start/shutdown of Database
and other Oracle Products

13 ### END INIT INFO
14
15 #
16 #
17 # home's of oracle products
18 #
19 # oracle db, listener, em
20 ODB_HOME="/appl/oracle/product/10.2.0/db_1"
21 # oracle http server
22 OHS_HOME="/appl/orahs/product/10.2.0/db_1"
23 # oracle bi publisher
24 OBIP_HOME="/appl/orabip/OraHome_1"
25 #
26 # operating system users, owners of oracle
software products

27 #
28 # oracle db, listener, em
29 ODB_USER="oracle"
30 # oracle http server
31 OHS_USER="orahs"
32 # oracle bi publisher
33 OBIP_USER="orabip"
34
35 #
36 # oradb log file
37 #
38 DBORALOG="/tmp/dbora.log"
39
40 case "$1" in
41 start)
42 echo "`date` Begin of Oracle Start Block
43 # oracle database and listener
44 su - $ODB_USER -c "$ODB_HOME/bin/dbstart $ODB_HOME"
45 RET_DB=$?
46 # oracle bi publisher
47 echo "Starting BI Publisher..."
48 su - $OBIP_USER -c "nohup $OBIP_HOME/oc4j_bi/bin/oc4j -start
>>$OBIP_HOME/startbip.log &"

49 RET_BIP=$?
50 echo "Sleeping 60 sec..."
51 sleep 60
52 # oracle em
53 su - $ODB_USER -c "$ODB_HOME/bin/emctl start dbconsole"
54 RET_EM=$?
55 # oracle http server
56 su - $OHS_USER -c "$OHS_HOME/opmn/bin/opmnctl startall"
57 RET_HS=$?
58 echo "Sleeping 60 sec..."
59 sleep 60
60 # touch lock file
61 touch /var/lock/subsys/dbora
62 RET_TOUCH=$?
63 echo "`date` Start Returns: RET_DB=$RET_DB
RET_BIP=$RET_BIP RET_HS=$RET_HS RET_EM=$RET_EM
RET_TOUCH=$RET_TOUCH" | tee -a $DBORALOG

64 echo "End of Oracle Start Block"
65 ;;
66 stop)
67 echo "`date` Begin of Oracle Stop Block..." | tee -a $DBORALOG
68 # oracle http server
69 su - $OHS_USER -c "$OHS_HOME/opmn/bin/opmnctl stopall"
70 RET_HS=$?
71 # oracle bi publisher
72 echo "Stopping BI Publisher..."
73 su - $OBIP_USER -c "$OBIP_HOME/jdk/bin/java
-jar $OBIP_HOME/oc4j_bi/j2ee/home/admin.jar ormi://localhost:20002
oc4jadmin qwertz1 -shutdown force >>$OBIP_HOME/stopbip.log"

74 RET_BIP=$?
75 # oracle database and listener
76 su - $ODB_USER -c "$ODB_HOME/bin/dbshut $ODB_HOME"
77 RET_DB=$?
78 # oracle em
79 su - $ODB_USER -c "$ODB_HOME/bin/emctl stop dbconsole"
80 RET_EM=$?
81 # remove lock file
82 rm -f /var/lock/subsys/dbora
83 RET_RM=$?
84 echo "`date` Stop Returns: RET_DB=$RET_DB
RET_BIP=$RET_BIP RET_HS=$RET_HS
RET_EM=$RET_EM RET_RM=$RET_RM" | tee -a $DBORALOG

85 echo "End of Oracle Stop Block"
86 ;;
87 restart)
88 echo "`date` Begin of Oracle Restart Block.." | tee -a $DBORALOG
89 $0 stop
90 RET_STOP=$?
91 $0 start
92 RET_START=$?
93 echo "`date` Restart Returns `date`: RET_STOP=$RET_STOP
RET_START=$RET_START" | tee -a $DBORALOG

94 echo "End of Oracle Restart Block"
95 ;;
96 *)
97 echo "Usage: $0 {start|stop|restart}"
98 exit 1
99 ;;
100 esac
101
102 exit $?
Here is standard output of my "start" test:
vl094:/etc/init.d # ./dbora start
Sat Sep 29 21:51:01 CEST 2007 Begin of Oracle Start Block...
Processing Database instance "DB094": log file /appl/oracle/product/10.2.0/db_1/startup.log
Starting BI Publisher...
Sleeping 60 sec...
TZ set to Europe/Vienna
Oracle Enterprise Manager 10g Database Control Release 10.2.0.3.0
Copyright (c) 1996, 2006 Oracle Corporation. All rights reserved.
http://vl094.fla.net:1158/em/console/aboutApplication
Starting Oracle Enterprise Manager 10g Database Control ........................ started.
------------------------------------------------------------------
Logs are generated in directory /appl/oracle/product/10.2.0/db_1/vl094.fla.net_DB094/sysman/log
opmnctl: starting opmn and all managed processes...
Sleeping 60 sec...
Sat Sep 29 21:54:57 CEST 2007 Start Returns: RET_DB=0 RET_BIP=0 RET_HS=0 RET_EM=0 RET_TOUCH=0
End of Oracle Start Block

Here is standard output of my "stop" test:
vl094:/etc/init.d # ./dbora stop
Sat Sep 29 21:55:13 CEST 2007 Begin of Oracle Stop Block...
opmnctl: stopping opmn and all managed processes...
Stopping BI Publisher...
Processing Database instance "DB094": log file /appl/oracle/product/10.2.0/db_1/shutdown.log
TZ set to Europe/Vienna
Oracle Enterprise Manager 10g Database Control Release 10.2.0.3.0
Copyright (c) 1996, 2006 Oracle Corporation. All rights reserved.
http://vl094.fla.net:1158/em/console/aboutApplication
Stopping Oracle Enterprise Manager 10g Database Control ...
... Stopped.
Sat Sep 29 21:59:09 CEST 2007 Stop Returns: RET_DB=0 RET_BIP=0 RET_HS=0 RET_EM=0 RET_RM=0
End of Oracle Stop Block


Regards,
Flavio




No comments: