Operating System - HP-UX
1832855 Members
2935 Online
110047 Solutions
New Discussion

Re: Custom Start/Kill Script

 
Hill_1
Frequent Contributor

Custom Start/Kill Script

Hi all,
I would like to start a 3rd party application at rc3. I've custom a S/K script for the application. However, I'm doubtful of whether I could simply put any unique sequence number for the script or there is any rules for this?
Thanks in advanced.
Unix
9 REPLIES 9
A. Clay Stephenson
Acclaimed Contributor

Re: Custom Start/Kill Script

Hi:

THe answer is yes you can. If anything in your start script depends upon some other service begin started first at run-level 3 then simply make sure that your S filename comes later in lexical order. It is perfectly acceptable to have S209mycode and S209yourcode. S209mycode is first in lexical order so that it runs before S209yourcode. The standard convention is that the 'S' value + the 'K' value = 1000. That is not a requirement but it does tend to correctly order the start/stop. In this example you should have /sbin/rc3.d/S209yourcode and /sbin/rc2.d/K791yourcode. Of course, both of these should be symbolically linked to /sbin/init.d/yourcode.

The other convention is that there should be a file /etc/rc.config.d/yourcode which contains any variables and usually a 1 or 0 value to indicate whether the script should run at all.

Regards, Clay
If it ain't broke, I can fix that.
harry d brown jr
Honored Contributor

Re: Custom Start/Kill Script

Yes they are sorted in order. so S400 starts before S401.
Live Free or Die
Tom Danzig
Honored Contributor

Re: Custom Start/Kill Script

By convension, the "don't care" start and kill numbers are:

Start - S900
Kill - K100
Eugen Cocalea
Respected Contributor

Re: Custom Start/Kill Script

Hi,

You can assign numbers and a name as you wish but make sure that if you need something to be started before your application, put your application lexically 'after' the 'something'. Also, if another service needs your app, make sure your app starts before it.

E.
To Live Is To Learn
Michael Tully
Honored Contributor

Re: Custom Start/Kill Script

Hi,

You can assign any numbers that you wish to
use, however in saying that you may have
some dependancy with your application in
that perhaps your databases need to be
started first, in which case use a higher
number that your database to start and
a lower one to stop. You could start with
say S991startapp in rc3.d and K009stop in
rc2.d. The numbers when used should
generally add up to 1000.

HTH
-Michael
Anyone for a Mutiny ?
melvyn burnard
Honored Contributor

Re: Custom Start/Kill Script

Take a read of /usr/share/docs/start_up.txt on your system. this explains it all.
My house is the bank's, my money the wife's, But my opinions belong to me, not HP!
Volker Borowski
Honored Contributor

Re: Custom Start/Kill Script

Those numbers are like good old BASIC programming on Apple or C64 !

Be sure to keep enough gaps, or sooner or later, you need to rename everything to insert something additional :-)

Beside this there are no rules, just the mentioned recommendations.

Volker
Santosh Nair_1
Honored Contributor

Re: Custom Start/Kill Script

Just make sure that the numbers that you choose are unique. Although this isn't an absolute requirement, it does make it easier to see the order in which things get done.

That said, typically the startup/kill scripts are both one script located in /sbin/init.d with symbolic links to the approprate run levels for startup and kill, i.e. if I have a script called oracle, then the setup would be something like this:

/sbin/init.d/oracle
/sbin/rc2.d/K999oracle ->/sbin/init.d/oracle
/sbin/rc3.d/S999oracle -> /sbin/init.d/oracle

Also, the script should have startmsg and stopmsg funtions. These are the messages that it display on the console screen when starting/killing the processes. Take a look at /sbin/init.d/template for more details.

Hope this helps.

-Santosh
Life is what's happening while you're busy making other plans
James R. Ferguson
Acclaimed Contributor

Re: Custom Start/Kill Script

Hi:

I'd like to reinforce one key point about startup/shutdown order and the '1000' guideline.

First, if a start script is place in directory '/sbin/rc{X}.d' then its corresponding kill script is put in directory '/sbin/rc{X-1}.d'

A general rule-of-thumb is that the sequence number of the start script plus the sequence number of the kill script should add to 1000.

Also, choose the appropriate rc.d directory -- one (1) is for core services; two (2) is for multiuser run-state; three (3) is for networked, multi-user; and four (4) is for graphical interfaces. Depending on the processes you are starting, or stopping, you want to make sure prerequisite services exist.

Subsystems should be killed in the opposite order they were started. This implies that kill scripts will generally not have the same numbers as their start script counterparts. If two subsystems must be started in a given order due to dependencies (e.g., S200sys1 followed by S300uses_sys1), the counterparts to these scripts must be numbered so that the subsystems are stopped in the opposite order in which they were started (e.g., K700uses_sys1 followed by K800sys1). The '1000' rule leads to this behavior.

If you can't find the document file that Melvyn suggested you read, it is present here:

http://docs.hp.com/hpux/onlinedocs/os/startup.html

The document is a easy reading and will answer all of your questions.

Regards!

...JRF...