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

about RUNLEVELs -- was "debian rookie"



On Sat, Jan 25, 2003 at 08:09:29AM -0600, Jeff Hahn wrote:
> One quick question to get me going a little better...  How do
> you install services (apache, samba, whatever) and NOT have
> them start on system startup?

when i finally figured out HOW to figure this out, i can't tell
you how many lights came on. had to wear sunglasses for a week.
:)

you may already know this -- but here goes...



where's the auto-start stuff? why are all these services running?

/etc/inittab specifies the runlevel via this line:

	id:2:initdefault:

runlevel 2 (or whatever your default is) is describe there also,
and mine looks like this:

	l2:2:wait:/etc/init.d/rc 2

it runs the command "/etc/init.d/rc 2" -- that's a script, which
is passed the value "2".

have a look at the /etc/init.d/rc script; it takes its first
argument ($1 as is standard in shell scripts -- the value of
which, in this case, "2") and uses it to determine which
directory to scan:

	[ "$1" != "" ] && runlevel=$1
	#<snip>
	if [ -d /etc/rc$runlevel.d ]

so the first arg ("2") is stuffed into variable "$runlevel" which
is used to look for a directory /etc/rc?.d --

	# First, run the KILL scripts.
	#<snip>
		for i in /etc/rc$runlevel.d/K[0-9][0-9]*

it goes through the directory (/etc/rc2.d in our case)
and then executes every scrip there whose name starts with
"K-digit-digit"!

(it passes the arcument "stop" to each such script.

			startup $i stop

nothing to it!)

then, after all "kill" scripts are done, it looks for the startup
scripts:

	# Now run the START scripts for this runlevel.
	for i in /etc/rc$runlevel.d/S*

for each "S-digit-digit" script in /etc/rc2.d, it passes a
parameter of "start":

				startup $i start

you'll note that it also does some checking to see if the service
is likely to be running already; if you're coming from runlevel 4
which has sshd running, and you're entering runlevel 5 which
also has an S20ssh script, then it won't bother starting it...

turns out, most of those K?? and S?? scripts are just links back
to the original scripts hanging out under /etc/init.d/ . often,
the Kill and Start scripts are the very same script; they look at
their argument ("stop" or "start" as we saw above) and figure out
what to do based on that.

another common value you can use yourself is "restart":

	/etc/init.d/apache restart

that stops the service, waits a bit, and then starts it again.  (i
use that whenever i screw up apache's settings. which never, ever
happens.)



so, removing (or just renaming) the links in /etc/rc?.d/
directories will do the trick; any Kdigit-digit scripts will be
run to stop services, and Sdigit-digit scripts will be run to
start them.

update-rc.d is a good way to keep the debian package system
up-to-date on your intentions. (sure, you may manually rename or
remove enough files to stop the service from auto-starting, but a
future `apt-get upgrade` may -- or may not -- undo all your hard
work, if you work outside the packaging system.)

-- 
I use Debian/GNU Linux version 3.0;
Linux server 2.4.20-k6 #1 Mon Jan 13 23:49:14 EST 2003 i586 unknown
 
DEBIAN NEWBIE TIP #45 from Will Trillich <will@serensoft.com>
:
Troubled by DOS-FORMAT TEXT FILES? There are many ways
to get rid of the extra ^M characters. In VIM, try
	:set ff=unix
before saving the file (":opt" for more info); or, use perl:
	perl -pi.dos -e 's/\cM//g' filename*pattern.txt
("perldoc perlrun" for more info.)

Also see http://newbieDoc.sourceForge.net/ ...



Reply to: