cancel
Showing results for 
Search instead for 
Did you mean: 

about scripts in /etc/rc.d

Deepa_4
Occasional Contributor

about scripts in /etc/rc.d

Hi,

I like to know what is the significance of numbers in front of the softlinks in /etc/rc.d/rc3.d or rc6.d or...

The S indicates 'start' and K indicates 'kill'.
But what for the number?

For example I have seen S85httpd in rc3.d dir.
The number 85 stands for what?

Please brief

thanks in advance
11 REPLIES
Alexander Chuzhoy
Honored Contributor

Re: about scripts in /etc/rc.d

S85something will start before S86something
and that's the whole trick.
Mark Grant
Honored Contributor

Re: about scripts in /etc/rc.d

Yep, they don't have to be numbers. At least on your average Linux box they don't. Some systems don't even run them numerically but alphabetically which can get things in the worng order at times. If you want to see exactly what happens, have a look at /etc/rc. This is the "real" unix start up script but nowadays, generally runs things in the rc.* directories.
Never preceed any demonstration with anything more predictive than "watch this"
Karthik S S
Honored Contributor

Re: about scripts in /etc/rc.d

http://docs.sun.com/db/doc/805-7228/6j6q7uepi?a=view

They have explained everything neatly in the above link .. (who cares if it is a SUN site as long as the information provided applies to HP-UX aswell .. well it applies more or less)

-Karthik S S
For a list of all the ways technology has failed to improve the quality of life, please press three. - Alice Kahn
Deepa_4
Occasional Contributor

Re: about scripts in /etc/rc.d

What exactly i want to know is:

I will be writing a script that should be called when reboot is given. So i will have a soft link to my script in /etc/rc.d/rc6.d directory.

I have seen all the file are having some numbers. see below:

K05news -> ../init.d/news
K08iBCS -> ../init.d/iBCS
K09samba -> ../init.d/samba
K12squid -> ../init.d/squid
K25gpm -> ../init.d/gpm
K25httpd -> ../init.d/httpd
K55snmpd -> ../init.d/snmpd
S99reboot -> ../init.d/reboot

I will be giving name of my script link which will start with 'S' . But what number I have to assign?

Is there any order these scripts should be called based on the numbers?

thank you
Karthik S S
Honored Contributor

Re: about scripts in /etc/rc.d

Deepa,

If you want a script to be invoked upon reboot then you must name it starting with the character 'K' and place it in /etc/rc.d/rc6.d directory. You can give it any number but unique one.

ex:
K77your_script

-Karthik S S
For a list of all the ways technology has failed to improve the quality of life, please press three. - Alice Kahn
Jean-Luc Oudart
Honored Contributor

Re: about scripts in /etc/rc.d

init level 1,2,3 ...
if you have Snnxxx in rc2.d you will/should have Kmmxxx in rc1.d

The rule is mm + nn = 1000

The order is taken by this number , Therefore the last started daemons are killed first.

Jean-Luc
fiat lux
Jeroen Peereboom
Honored Contributor

Re: about scripts in /etc/rc.d

L.S.

As already said by other, the numbers determine the executing sequence of the scripts in the rcn.d directory. The 'n' is the runlevel (RedHat: 3 multi user, 5: Graphical multiuser). See /etc/inittab.

An easier way of maintaining all these softlinks is using chkconfig.
chkconfig -add service
chkconfig service on
chkconfig --list service

Check the manpage.
A commentline in your script may be needed. Check other scripts in /etc/init.d for an example.

JP.
Martin P.J. Zinser
Honored Contributor

Re: about scripts in /etc/rc.d

The thing you want to keep in mind is the prerequisits that your script needs. Lets say it still needs the network, so you have to select a number higher than used for the network start/stop script.

Greetings, Martin
Olivier Drouin
Trusted Contributor

Re: about scripts in /etc/rc.d

And you can symlink your K01blah and S01blah to the same script.

The K01blah symlink will be called with "stop" argument and the S01blah will be called with "start" argument
Stuart Browne
Honored Contributor

Re: about scripts in /etc/rc.d

For the record, the number doesn't have to be unique.

Simply, /etc/rc.d/rc gets called by 'init', and does simple loops like:

for i in /etc/rc.d/rc6.d/K*
do
$i stop
done

(NOTE: On RH, it literally *IS* "for i in"!)

The numbers give the basic order of execution. All you really need to take into account is that your process is started after it's required subsystems are started, and stopped before it's required subsystems are stopped.

Usually this means you have a high S value (for rc 2/3/4/5), and a low K value (for rc 0/6).

As was said in the previous post, the values for S and K should add up to 100, but that isn't a 'rule', it's just a good guideline for keeping the start-up/shut-down orders equivalent.

Also note, that the order numbers are *ALWAYS* zero padded, i.e.:

S99MyRoutine
K01MyRoutine

To get an idea what order the start/stop will occur in, simply issue:

echo /etc/rc.d/rc3.d/S*

This will show the order they'll be executed in.
One long-haired git at your service...
Deepa_4
Occasional Contributor

Re: about scripts in /etc/rc.d

thanks for all. So clear.

Deepa