8

Why do scripts beginning with an 'S' exist in /etc/rc.d/rc{0,6}.d? Will there be trouble if I change the 'S' to a 'K'?

Is the behavior of the system changed when it halts/reboots?

slhck
  • 223,558
  • 70
  • 607
  • 592
Qian
  • 481
  • 1
  • 5
  • 13

2 Answers2

12

Yes, the traditional system V init style (what that is) makes symlinks that start with S, or K. those with S means "start", and they are run with the "start" parameter when that runlevel is entered. Those with K means "kill", those services are run with the "stop" parameter when that runlevel is entered. This makes the different run levels have different sets of services running. If you cange one from S to K the server won't be started, it will be stopped then. That may or may not be a problem depending on whether or not it was a critical service.

BTW, this method is being obsoleted by newer, dependency based startup systems in newer Linux distros.

Keith
  • 8,013
  • 1
  • 31
  • 34
  • I mean changing a link in rc0.d or rc6.d, will this change the behavior of the system? – Qian Jul 10 '11 at 12:29
  • Why don't you elaborate on your original question so we don't have to guess what you really mean? Thanks. – Keith Jul 10 '11 at 12:33
  • 1
    I think in both of those it doesn't make sense to have any "S" scripts since 0 is shutdown and 6 is reboot. Runlevels 0 and 6 aren't normally "exited from." If you want to disable a script from running on shutdown or reboot the right thing to do is remove the symlink. If you want to change the order it executes, you want to "rename" the symlink to modify the two digit number, i.e. change `K10whatever` to `K20whatever`. You should consult the script itself to know what it actually does. – LawrenceC Jul 10 '11 at 14:01
  • 1
    This is a really bad answer. The OP was specifically asking about the implication of having a start script in the shutdown/restart directory. – aaa90210 Jul 09 '13 at 00:01
  • @aaa90210 No, he wasn't. – Keith Jul 10 '13 at 00:19
  • @Keith Yes he was, the question still specifically referrers to {0,6} runlevels which you did not mention in your answer. Furthermore, his first comment again *specifically* refers to rc0 and rc6, which you replied with another inane remark. Terrible contributor, I don't use this site often enough to down-vote you, but at least I can leave this note for others. – aaa90210 Jul 18 '13 at 11:35
  • @aaa90210 He simply asked if there would be a change in behavior if he changed a prefix from S to K. Without knowing exactly what script, or what the script does (which the OP doesn't say), it is impossible to give a more specific answer. Some halt scripts have backwards semantics. – Keith Jul 18 '13 at 18:41
  • Yes I was. I thought if there were any answers, the OP had to select one as the best. Now I know it's not necessary. – Qian Aug 30 '14 at 12:23
0

The best answer I found to this on another website is that the K and the S are ignored on run levels 0 and 6 as the system will simply executed all of those scripts with the stop command in alpha-numeric order anyway... So S or K doesn't even matter.

I can prove this in a default install of Ubuntu where I have examples like the following:

K20restsrv K20zfs-mount K20zfs-share

S31umountnfs.sh S40umountfs S60umountroot S90halt

The K examples have stop commands within those scripts. The scripts also specify default run levels when the start and stop commands will run like it shows default start on run levels 2,3,4,5 and default stop on 0,1,6

  • 1
    Yes the K and S are ignored. On my old system, the order of execution would be changed. K first, then S. I had my own answer then, but in the wrong place. You can check out the revision history. Anyway, it doesn't matter now, since we have systemd. – Qian Aug 30 '14 at 12:30
  • Huh! "alpha-numeric order"! K comes before S anyway. – Qian Aug 30 '14 at 12:33