1827245 Members
2258 Online
109716 Solutions
New Discussion

Script at boot up.

 
SOLVED
Go to solution
Rafael Casero
Regular Advisor

Script at boot up.

I have a couple of scripts I need to put in place.

I would like to execute them when the system comes up and shuts down. Tese are to bring the databeses and shut them down.

Can someone help me set them up.

Where would it be the best place to put them and how.

Thanks...

14 REPLIES 14
James R. Ferguson
Acclaimed Contributor
Solution

Re: Script at boot up.

Hi Rafael:

Start-up and shutdown scripts are quite easy to implement. In fact, a template exists to expedite the process: '/sbin/init.d/template'.

I urge you to take the few minutes needed to read the whitepaper below. It applies to all HP-UX releases since 10.x.

http://www.docs.hp.com/en/934/startup.pdf

A summary of it's key points can also be found in the manpages for 'rc(1M)':

http://www.docs.hp.com/en/B2355-60127/rc.1M.html

Regards!

...JRF...

Ninad_1
Honored Contributor

Re: Script at boot up.

Hi,
The the best place to put your startup and shutdown scripts is /sbin/init.d
Here you have got a file called template which can be used as the template for the script which is used during system starup and shutdown. You can modify this template to put your commands for database startup and shutdown in the corresponding sections of start and stop.
Then create the soft links in /sbin/rc3.d as
ln -s /sbin/init.d/oracle Snnnoracle [ Decide this number nnn depending upon when the script should run - the number decides when that script will be run.(higher number scripts will run after the lower number script has been run.)
Also create a link in /sbin/rc2.d
ln -s /sbin/init.d/oracle Knnnoracle

There should be standard scripts available for startup and shutdown and am sure someone here might be able to provide you sample script as well.

Regards,
Ninad
A. Clay Stephenson
Acclaimed Contributor

Re: Script at boot up.

First make sure that all environment variables are set and exported in your script such as ORACLE_SID and PATH.

Next, look in /sbin/init.d for a file called 'template' and copy it to a new file (e.g. /sbin/init.d/dbscript). You will find 4 sections with a case statement: 1) start_msg, 2) start, 3) stop , and 4) stop_msg. Each of these is executed by the rc command when the machine is booted and shutdown. The start_msg and start sections are executed on startup and the stop_msg and stop sections are executed on shutdown. The xxx_msg sections simply echo to the console. The start section should call your "real" startup script and the stop section should call your "real" shutdown script.

So far, you have actually done nothing because those scripys in /sbin/init.d are not actually invoked by rc; you must now create symbolic links. You will probably want to start execution in run-level 3, so create a symbolic link in /sbin/rc3.d (e.g ln -s /sbin/init.d/dbscript /sbin/rc3.d/S750dbscript. The scripts under a giver rc.N directory are executed in lexical order so if your dbscripts requires that other services such as NFS be up first that you Snnn values occur after those that you need first. By convention, the shutdown scripts are executed at run-level - 1 from the start scripts and if you choose 3 digit numbers (zero-padded if necessary) that add
to 1000, the startup and shutdown scripts almost always occur in correct sequence.

Your symbolic link for the shutdown script should be something very close to this:

ln -s /sbin/init.d/dbscript /sbin/rc2.d/K250dbscript.
If it ain't broke, I can fix that.
Sandman!
Honored Contributor

Re: Script at boot up.

Rafael,

If you have a valid "oratab" file and the ORACLE_HOME variable is defined and exported, then follow the steps below...

1. Install the script in the /sbin/init.d directory, name it oracle.

2. make symbolic links to the 2nd and 3rd run-levels for stopping and starting oracle respectively, like...

ln -s /sbin/init.d/oracle /sbin/rc3.d/S900oracle
ln -s /sbin/init.d/oracle /sbin/rc2.d/K100oracle

~hope it helps
Victor Fridyev
Honored Contributor

Re: Script at boot up.

Hi,

In addition to above, please look at an example of simple oracle start/stop script. In order to use it, create /etc/rc.config.d/oraconf file, which may help you to switch on/off oracle startup.

Please take into account that the script works only when all your databases are built with the same ORACLE_HOME. Additionally pay your attention that listener is started up in its simplest form.
You may need to update the script according to existing conditions.

Also look at $ORACLE_HOME/bin/dbshut script and add parameter IMMEDIATE or TRANSACTIONAL for each shutdown command in it.
Entities are not to be multiplied beyond necessity - RTFM
Rafael Casero
Regular Advisor

Re: Script at boot up.

The DBA created the script, scripts on runs when you su - oracle user.

How would I get this script to start up when the system boots up ? if it can be done.

Thanks,
Sandman!
Honored Contributor

Re: Script at boot up.

>>The DBA created the script, scripts on runs when you su - oracle user.

>>How would I get this script to start up when the system boots up ? if it can be done.

Assuming the script your DBA has created is called "start_stop_oracle". Copy this script to "/sbin/init.d" directory. Now create symbolic links to this script in the 2nd and 3rd run levels for stopping and starting it as follows:

# ln -s /sbin/init.d/start_stop_oracle /sbin/rc2.d/S900start_stop_oracle
# ln -s /sbin/init.d/start_stop_oracle /sbin/rc2.d/K100start_stop_oracle

That's all you have to do for the "script to start up when the system boots up".

~cheers
Rafael Casero
Regular Advisor

Re: Script at boot up.

The problem is that this script will only execuye has oracle user, it woun't start hass root.

I have done this but no luck...
A. Clay Stephenson
Acclaimed Contributor

Re: Script at boot up.

The su - oracle xxxx command almost certainly has an Achilles' heel and that is the sourcing of oracle .profile. When run interactively, all is well; however, .profile almost certainly has commands like tput, tset, tab, ... which expect stdin to be a terminal-like device which is not the case under rc. The .profile is intended to set and export needed environment variables but this very .profile can cause .profile to hang when stdin is not a tty device. The preferred approach (Method A) is to create a file, e.g. /usr/local/bin/oraenv.sh which sets and exports any needed environment variables. Then both the rc startup/shutdown script and oracle's .profile should source this file using the dot operator.

e.g.
. /usr/local/bin/oraenv.sh

(oraenv.sh must not contain a return or exit statement because this sourced file is actually a part of the foreground process.

That will safely source the file and now you
do not use the "-" in the su command so that .profile is not used.

Method B is to continue to use "-" and alter .profile so that those tty related commands are ignored:

if [ -t 0 ]
then #stdin is a tty device
tput ...
tset ...
stty ...
tabs
fi
If it ain't broke, I can fix that.
AwadheshPandey
Honored Contributor

Re: Script at boot up.

Rafael Casero
Regular Advisor

Re: Script at boot up.

I must be doing something wrong on my syntax...

miaux10: / =>ln -s /sbin/init.d/oracle_ctl.sh /sbin/rc3.d/S900su - oracle -c '/sbin/init.d/orcale_ctl.sh start'
Usage: ln [-f] [-i] [-s] f1 f2
ln [-f] [-i] [-s] f1 ... fn d1

Please help..
A. Clay Stephenson
Acclaimed Contributor

Re: Script at boot up.

What is this nonsense?

ln -s /sbin/init.d/oracle_ctl.sh /sbin/rc3.d/S900su - oracle -c '/sbin/init.d/orcale_ctl.sh start'

Does oracle_ctl.sh even understand the start|stop|start_msg|stop_msg arguments?

If not, you start with a copy of the template file and within the start) section of you you do your "su - oracle -c oracle_ctl.sh". Your symbolic links link thios template file copy to entries in the rc.N directories. The ln -s command will not pass command line arguments. Man ln would probably help.

I patiently explained all this above and you chose to ignore it. Also, you would be wise to heed my warning about "su - oracle" rather than "su oracle".
If it ain't broke, I can fix that.
Rafael Casero
Regular Advisor

Re: Script at boot up.

Yes, it understands it |start |stop.

James R. Ferguson
Acclaimed Contributor

Re: Script at boot up.

Hi Rafael:

You need to symbolic link like this:

# ln -s /sbin/init.d/s_k_oracle /sbin/rc3.d/S900s_k_oracle

NOTE that the basename ("s_k_oracle") is used both in the basename of the '/sbin/init.d' directory and the '/sbin/rc2.d' directory. Do the same kind of thing for the 'kill' script:

# ln -s /sbin/init.d/s_k_oracle /sbin/rc2.d/K100s_k_oracle

...but use "K" instead of "S" and follow the "rule-of-1000".

Now, *inside* the '/sbin/init.d/s_k_oracle script you should place the command to switch to the oracle user:

# su oracle -c ' ... ' #...fill in appropriately.

*Now* test by doing:

# /sbin/init.d/s_k_oracle start
# /sbin/init.d/s_k_oracle stop

If you have used the '/sbin/init.d/template' as a guide, this should work quite well.

Look at the whitepaper I originally suggested, again, along with the 'rc(1M)' manpages and a simple startup script like:

# /sbin/init.d/cron

Regards!

...JRF...