Operating System - HP-UX
1833784 Members
2290 Online
110063 Solutions
New Discussion

/sbin/init.d script problem

 
SOLVED
Go to solution
CJENSEN_1
Regular Advisor

/sbin/init.d script problem

I have created startup and shutdown scripts to manage oracle during a reboot or power failure. The scripts do appear to work, however everything is not 100%. It appears that the shutdown scripts are being executed twice. Also, there is a bunch of "junk" being written to rc.log. This is on a rp5470 running 11.11.

The startup script is in /sbin/rc3.d, and the shutdown script is in /sbin/rc2.d. Perhaps I'll attach the scripts and someone in the know can comment on it (this is all new to me).
16 REPLIES 16
Ravi_8
Honored Contributor

Re: /sbin/init.d script problem

Hi,

scripts placed under /sbin/init.d and softlink to /sbin/rc2.d and rc3.d. and it works well.

never give up
Keith Bryson
Honored Contributor

Re: /sbin/init.d script problem

Hi there

Make sure that you ONLY have 2 links created as follows (substitue myscriptname for your script name!!):

ln -s /sbin/init.d/myscriptname /sbin/rc2.d/K001myscriptname
ln -s /sbin/init.d/myscriptname /sbin/rc3.d/S999myscriptname

When you do 'll -R /sbin | grep myscriptname' you should only have 3 entries.


To prevent the 'junk' in the rc.log, you should remember to re-direct your output from each xxx_start_db line that you have in your script - for example:

/u05/rpsb_admin/tiger_start_db >/tmp/logfile
or
/u05/rpsb_admin/tiger_start_db >/dev/null

The latter is not preferable as you won't see any errors!!

Hope that helps - Keith
Arse-cover at all costs
Keith Bryson
Honored Contributor

Re: /sbin/init.d script problem

In your scenario, if you must use two separate scripts for stop and start (you'd normally combine them into one and use a case statement to handle the passed start/stop rc argument) still create the links where the K001myscriptname points to your stop script (put it in /sbin/init.d) and S999myscriptname points to your start script (also put it in /sbin/init.d).

Keith
Arse-cover at all costs
Keith Bryson
Honored Contributor

Re: /sbin/init.d script problem

To re-iterate:

ln -s /sbin/init.d/mystopscript /sbin/rc2.d/K001myscriptname
ln -s /sbin/init.d/mystartscript /sbin/rc3.d/S999myscriptname

When you do 'll -R /sbin | egrep "mystopscript|mystartscript"' you should only have 4 entries.

Keith
Arse-cover at all costs
Yogeeraj_1
Honored Contributor

Re: /sbin/init.d script problem

hi,

also have a look at the attached document which discusses about HP-UX system startup and configuration models.

regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Yogeeraj_1
Honored Contributor

Re: /sbin/init.d script problem

attachment
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
CJENSEN_1
Regular Advisor

Re: /sbin/init.d script problem

1) Yogeerah, the document you attached on startup and configuarion - it talks about 10.x. Since this server is on 11.11, are there any changes?
2) I don't place anything under /etc/rc.config.c. Granted, I am using two separate scripts - so I take it this is a non-issue?
3) I do not have any arguments to pass to the scripts, (hence no start_msg, start, stop_msg, or stop commands) - will this be an issue?
Thanks.
CJENSEN_1
Regular Advisor

Re: /sbin/init.d script problem

One further question - with regards to the naming conventions for the link files. The document mentions they should only be 10 characters long - myne exceed this. Is this important?
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: /sbin/init.d script problem

You are essentially breaking all the rules. There should be one script to do both the startup and shutdown. Your specific problem since you don't bother with those pesky arguments is that the script is being called twice -- once with 'stop_msg' and again with 'stop'. Since your code doesn't branch, it executes twice. The same rules apply as in 10.20; play by the rules and you should be fine.
If it ain't broke, I can fix that.
Stephen Keane
Honored Contributor

Re: /sbin/init.d script problem

Its not you that passes the arguments to the script, its the operating system.

The operating system will call the script twice on startup, once passing it the argument 'start_msg', the second time passing the argument 'start'. The first call is to allow the script to output a short line that will be displayed on the console (usually between [ ]'s), the second call is to actual start whatever the script is going to start.

The operating system will call the script twice on system shutdown, once passing it the argument 'stop_msg', the second time passing it the argument 'stop', for similar reasons.

Thus you should have a control script in /sbin/init.d which does something like ...

#!/sbin/sh

# comments
#

PATH=... whatever ...
export PATH

case "$1" in

"start_msg") echo "Starting XYZ" ;;

"start") start_script ;;

"stop_msg") echo "Stopping XYZ" ;;

"stop") stop_script ;;

esac

exit 0;

############


You start_script/stop_scripts can be wherever you like, provided you set the path correctly in the control script. You need to create a Kxxxx link in /sbin/rc2.d and a Sxxx link in /sbin/rc3.d to the control file.
CJENSEN_1
Regular Advisor

Re: /sbin/init.d script problem

Thanks. Stephen Keane - can I just clarify your comments please - I take it that I just need one script in /sbin/init.d, and it gets called from rc2.d/rc3.d for stop/start respectively. Is this correct? Do I need anything in the /etc/rc.config.d directory?
A. Clay Stephenson
Acclaimed Contributor

Re: /sbin/init.d script problem

You don't have to have anything in /etc/rc.config.d; that is an HP-UX convention and provides an easy way to set environment variables and most typically to put a flag variable set to 1 or 0 to run or not to run the related rc script. The 'by the rules' method is to have a file in /etc/rc.config.d of the same name as the script in /sbin/init.d and the init.d script sources the /etc/rc.config.d file via the "." (dot) operator.
If it ain't broke, I can fix that.
CJENSEN_1
Regular Advisor

Re: /sbin/init.d script problem

With regards to the /sbin/init.d/template file:
I'm using this file to re-build my scripts. Since my script only starts and stops Oracle services - the section in that template file that is "Kill the named Process(es), $1=" - I don't understand how this section applies to my start/stop scripts. Can I ignore this section?
A. Clay Stephenson
Acclaimed Contributor

Re: /sbin/init.d script problem

Yes, the killproc() function is a handy way of matching process names (e.g. myproc) to PID's for kill scripts. You don't have to call the function but typically, you leave the function in the script but just don't call it.
If it ain't broke, I can fix that.
CJENSEN_1
Regular Advisor

Re: /sbin/init.d script problem

Thanks everyone for your responses - it is much appreciated. Everything is 100% now. I have assigned points to this thread.
CJENSEN_1
Regular Advisor

Re: /sbin/init.d script problem

Thanks