1833299 Members
2748 Online
110051 Solutions
New Discussion

Re: rc scripts

 
Tracey Hammer
Occasional Contributor

rc scripts

For links to scripts that are in the /sbin/rcx.d directories do the sequence numbers HAVE to be 3 digits. Can they be 2 or 4 digits.


For instance /sbin/rc.d/S555webservices. Can I use /sbin/rc.d/S55webservices or /sbin/rc.d/S555%.webservices
10 REPLIES 10
melvyn burnard
Honored Contributor

Re: rc scripts

The way of doing these is to keep them as S??? or K???
This is due to the way they are sorted to be run. If you do want it to run as S/K55, then add in the leading 0
To quote from the file /usr/share/doc/start_up.txt:

The /sbin/rc#.d (where # is a run-level [0..6]) directories are startup and shut
down sequencer directories. They contain only symbolic links to startup/shutdown
scripts in /sbin/init.d that are executed by /sbin/rc on transition to a specif
ic run level. For example, the /sbin/rc3.d directory contains symlinks to script
s that are executed when entering run level 3. (There is more information on /sb
in/rc in Section 2.4, "Run Levels and /sbin/rc").
These directories contain two types of link files: start links and kill links. S
tart links have names beginning with the capital letter "S" and are invoked with
the "start" argument at system boot time or on transition to a higher run level
. Kill links have names beginning with the capital letter "K" and are invoked wi
th the "stop" argument at system shutdown time, or when moving to a lower run le
vel.
Further, all link files in a sequencer directory are numbered to ensure a partic
ular execution sequence. Each script has, as part of its name, a three digit seq
uence number. This, in combination with the start and kill notation, provides al
l the information necessary to properly startup and shutdown a system.
My house is the bank's, my money the wife's, But my opinions belong to me, not HP!
Rajiv Singhal
Advisor

Re: rc scripts

Yeah the sequence number is a three digit number. Look for "man rc" & it has answer to your question.

Thanks
Rajiv
Ken Penland_1
Trusted Contributor

Re: rc scripts

from the manpage:
A three digit number is used for sequencing scripts within the sequencer directory. Scripts are executed by type (start or kill) in alphabetical order as defined by the shell. Although it is not recommended, two scripts may share the same sequence number.

So it is recommended to use three numbers, though I have seen instances where two numbers were used and it still works, I think three is standard to simplify sorting out which script gets run first.
'
Biswajit Tripathy
Honored Contributor

Re: rc scripts

Yes, the numbers have to be three digits to maintain
the format and redability. If you want to use 55, then
use S055.

Ofcourse, nothing will stop you if you use 2 digits, but
you shoud know that S55XXXX script will probably run
AFTER S500YYYY script.

- Biswajit

:-)
Tracey Hammer
Occasional Contributor

Re: rc scripts

ok, so in summary the 3 digit numbering system is for consistency but if its 2 digts or 4 digits that will not keep the script from working. We have inherited some hp servers from another account and some of their customized scripts have 2 digits. Thnx.
Dave La Mar
Honored Contributor

Re: rc scripts

Tracey-
I can sympathize with your inheritance. Now if you want to "standardize", attached is the doc I have used many times. You'll find it has test scenarios for you to try after your modifications. It was written during the 10.X era but I have been using it for on 11.X startups as well.

Best of luck.

regards,

dl
"I'm not dumb. I just have a command of thoroughly useless information."
Daryl Much
Frequent Advisor

Re: rc scripts

FWIW, I believe the S and K numbers are intended (but not required) to add up to 1000. this will help them to start and stop in consistent order. Note, for instance, the nfs scripts:

0 lrwxr-xr-x 1 root root 23 Jan 21 18:41 rc1.d/K570nfs.client -> /sbin/init.d/nfs.client
0 lrwxr-xr-x 1 root root 21 Jan 21 18:41 rc1.d/K600nfs.core -> /sbin/init.d/nfs.core
0 lrwxr-xr-x 1 root root 23 Jan 21 18:41 rc2.d/K900nfs.server -> /sbin/init.d/nfs.server
0 lrwxr-xr-x 1 root root 21 Jan 21 18:41 rc2.d/S400nfs.core -> /sbin/init.d/nfs.core
0 lrwxr-xr-x 1 root root 23 Jan 21 18:41 rc2.d/S430nfs.client -> /sbin/init.d/nfs.client
0 lrwxr-xr-x 1 root root 23 Jan 21 18:41 rc3.d/S100nfs.server -> /sbin/init.d/nfs.server


Chuck Davis
Kent Ostby
Honored Contributor

Re: rc scripts

The process is controlled out of /etc/rc and /etc/rc.utils.

Here's the portion that creates (for instance) the start list:

while [ $lvl -le "$new" ]; do
get_scripts $lvl S |
while read name descrip; do
if [ -s "$name" ]; then
add_list "$name start" "$descrip"
found=1
fi

Note that its adding "$name start" to the list of things to run.

The reading from get_scripts is output from the following:

get_scripts() {
state=$1
mode=$2
dir=/sbin/rc${state}.d
# Fix for DSDe444244:
# Use of unspecified \ls\ in /sbin/rc can cause rc script failure
# ls has been replaced with /sbin/ls
/sbin/ls $dir 2>/dev/null

So the only limitation on the name is that it must start with an "S" or "K" and that it will be returned in order of the 'ls' .

So I guess you could even do something like:

Sa_MyCommand

and it would work.

It would just sort it to wherever "Sa" would fall amongst such things as s0100

Best regards,

Oz
"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
A. Clay Stephenson
Acclaimed Contributor

Re: rc scripts

You are perfectly free to do whatever you like as long as the names begin with 'S' or 'K' BUT you should be aware on the consequences. THe files are processed in lexical order, so, for eaxample S100xxx, S200xxx, S499xxx will be processed before S55xxx. This is the significance of the leading zeroes. It is also perfectly legal to have multiple S055 but not necessarily wise. If your daemons and other processes depend upon other services (e.g. NFS being available) then the ordering matters a great deal. BY CONVENTION, if the service starts at run-level N then it should be halted at run-level N - 1. BY CONVENTION, the KNNNxxx values + the Snnnxxx values should add to 1000 because this tends to correctly order the startup/halt sequences. For example in rc2.d you might have K050mystuff which would be linked to rc3.d/S950mystuff.
If it ain't broke, I can fix that.
Cem Tugrul
Esteemed Contributor

Re: rc scripts

Hi Tracey,

As additional please take a look of my attachment pdf.

Good Luck
Our greatest duty in this life is to help others. And please, if you can't