[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: question on sysvinit



Sven> Hi all I wanted to know why that when changing runlevels from
Sven> say 2 to 3, the KILL links of _3_ and not 2 get executed before
Sven> starting the START links of 3...?

Marshal> I think because K comes before S.  So switching run levels
Marshal> only runs the scripts in the runlevel dircetory (in your case
Marshal> rc3.d).  The kill scripts of 2 have already been run,
Marshal> presumably when you first boot up, or when you switched to
Marshal> runlevel 2.

Sven> Hmm, my idea of the K links have been to "clean up" the system
Sven> so as to be able to go into a different state / runlevel... but
Sven> I am unsure now.

Sven> I mean, at that point you're leaving runlevel 2 and it would
Sven> only make sense to stop those runlevel's services and not the
Sven> new runlevel's, right?

Marshal> Maybe, but I think to have what you want, you'll need start
Marshal> up scripts and kill scripts for both going into the runlevel
Marshal> and leaving the

Sven> But at first, the system isn't in any runlevel and hasn't any
Sven> services up, and so it won't need to stop anything and thus K
Sven> links for runlevel S (or whatever the first actual runlevel is)
Sven> don't make sense to me.

Sven> Someone please shed some light on this for me as I want to
Sven> understand this.

What you're missing (and it's easily missed) is that the runlevel
changes are _stateless_.

It doesn't matter what the _old_ level is, the system will always
execute the same scripts upon entering the same (new) level.  So, for
each level, the K scripts "clean up" everything that is not needed _on
the new level_, potentially doing some redundant work (ie. killing
servers that are not running because they are not part of the old
level).  Then the S scripts start everything that is needed, again
potentially restarting things that were already active on the old
level (although Debian avoids that as a matter of optimization).

Why is it this way?  Well, there's really no way to tell init to
execute programs upon _exiting_ a runlevel, or upon a transition from
one level to another; the /etc/inittab that defines runlevels is
one-dimensional.  So the transition must be defined independently of
the old level.

-- 
Ian Zimmerman, Oakland, California, U.S.A.
In his own soul a man bears the source
from which he draws all his sorrows and his joys.
Sophocles.



Reply to: