From: joe@morton.rain.com (Joe Moss)
Subject: Re: jobs to run at powerdown
Organization: Morton & Associates, Inc.
Date: Tue, 6 Oct 1992 21:30:24 GMT

larry@gator.rn.com (Larry Snyder) writes:

>bill@bilver.uucp (Bill Vermillion) writes:

>>Perhaps you would have more success if you put it in /etc/rc0.d  :-)

>I did -- aren't the scripts executed in sucession?

>ie: -- if you are in init state 3 and go to 0, isn't everything
>in rc2.d run, followed by everything in rc1.d, then everything in
>rc0.d?

No they're not.  Well at least not by default - you could change
things around if you really wanted to, I suppose.

Here is the default inittab included with Dell SVR4:

ap::sysinit:/sbin/autopush -f /etc/ap/chan.ap
ak::sysinit:/sbin/wsinit 1>/etc/wsinit.err 2>&1
ck::sysinit:/sbin/setclk </dev/console >/dev/sysmsg 2>&1
bchk::sysinit:/sbin/bcheckrc </dev/console >/dev/sysmsg 2>&1
is:3:initdefault:
r0:0:wait:/sbin/rc0 off 1> /dev/sysmsg 2>&1 </dev/console
r1:1:wait:/sbin/rc1  1> /dev/sysmsg 2>&1 </dev/console
r2:23:wait:/sbin/rc2 1> /dev/sysmsg 2>&1 </dev/console
r3:3:wait:/sbin/rc3  1> /dev/sysmsg 2>&1 </dev/console
r5:5:wait:/sbin/rc0 reboot 1> /dev/sysmsg 2>&1 </dev/console
r6:6:wait:/sbin/rc6 reboot 1> /dev/sysmsg 2>&1 </dev/console
sd:0:wait:/sbin/uadmin 2 0 >/dev/sysmsg 2>&1 </dev/console
fw:5:wait:/sbin/uadmin 2 2 >/dev/sysmsg 2>&1 </dev/console
rb:6:wait:/sbin/uadmin 2 1 >/dev/sysmsg 2>&1 </dev/console
li:23:wait:/usr/bin/ln /dev/systty /dev/syscon >/dev/null 2>&1
sc:234:respawn:/usr/lib/saf/sac -t 300

The 'is:3:initdefault:' line indicates that when the system is
brought up, it should enter run level three as the default (multiuser)
run level.

But the commands in the /etc/rc2.d directory get run
at startup - I think this is probably what is confusing you.
The /etc/rc2.d/S* scripts are run *not* because the system goes
through the various levels until it gets to three, but because of
the '23' field on the line with the '/sbin/rc2' command.

Init changes to a specific run level by parsing the inittab file
and executing any lines that have that run level's value in the
second field.  So when the system is brought up it will run the
lines (not counting the sysinit stuff):

r2:23:wait:/sbin/rc2 1> /dev/sysmsg 2>&1 </dev/console
r3:3:wait:/sbin/rc3  1> /dev/sysmsg 2>&1 </dev/console
li:23:wait:/usr/bin/ln /dev/systty /dev/syscon >/dev/null 2>&1
sc:234:respawn:/usr/lib/saf/sac -t 300

Again it runs /sbin/rc2 because there is a 3 in the second field,
not because it goes to init state 2 before proceeding to 3.

Now, when you do a shutdown, it will again parse the inittab file,
this time looking for lines containing a zero in the second field, thus:

r0:0:wait:/sbin/rc0 off 1> /dev/sysmsg 2>&1 </dev/console
sd:0:wait:/sbin/uadmin 2 0 >/dev/sysmsg 2>&1 </dev/console

Therefore it will run the scripts in /etc/rc0.d (the K* one's first,
followed by the S* scripts).

BTW, you can ignore that 'sd' line - it's just there for backwards
compatibility - it doesn't get run because the '/sbin/rc0 off' shuts
down the system before init has a chance to do anything else.

>-- 
>Larry Snyder                                    internet: larry@gator.rn.com
>keeper of the Gator                                  uucp: uunet!gator!larry
-- 
Joe V. Moss                             |   joe@morton.rain.com
Morton & Associates                     |  joem@m2xenix.psg.com
7478 S.W. Coho Ct.			|         - or -
Tualatin, OR 97062-9277                 |  uunet!m2xenix!morton!joe
Newsgroups: comp.unix.sys5.r4