Jacob,
  I will attempt to help you with your understanding of runlevels and
how to configure services to start or stop properly.

Runlevels
        As you noted there are six runlevles in a Linux system. Runlevel
0 is to shut down the machine and runlevel 6 is to reboot the machine.
Runlevel 1 is single user mode, or maintenance mode. I believe this is
true for all distos of Linux. Now runlevels 2 through five are always
different between distros. In Debian/Ubuntu/Kbuntu runlevels 2-5 are the
exact some, multiuser with X windows. Red Hat/Fedora and others will use
runlevel 2 as multiuser console only (good for servers) and runlevel 5
for multiuser with X windows. Even with that there are still usually two
runlevels that are unused. With these you can allow certain things to be
enabled or disabled. For instance, if you wanted to change between
windows managers, so runlevel 4 may start kdm and kill gdm and runlevel
5 may start gdm and kill kdm. Not the best example, but shows what you
can do.

Rc.d
        So now that we talked about runlevels and what they do, lets
talk about customizing them to do what we want. Since I use Debian, the
references will be to that, for other distros, the layout is similar and
you should be able to get the idea. First of all, there is a directory
where all the init scripts are located (/etc/init.d) these are scripts
that start, stop, etc... things like cron, mysql, apache, etc...
Basically any of these scripts can be started or stopped using
runlevels. In Debian there are directories named /etc/rc[0...6,S].d and
these correspond to what services start at which runlevel. The rcS.d
directory will run at system start-up and you really don't want to mess
with it. So, you want to make MySQL start when you boot your computer?
Find out what runlevel you are currently in by typing /sbin/runlevel.
The number will be your current runlevel. Since most people only use one
runlevel you only have to make the change in one directory. If I am in
runlevel 2, then I (as root) would change to /etc/rc2.5. Doing a list
will show all the services started and stopped for that runlevel
(excluding the ones in /etc/rcS.d/), You will notice that the files have
the format SXXname for starting a service and KXXname for stopping a
service. S stands for Start and K stands for Kill. The XX is the number
order in which the service will be started. The lower the number the
more firstly it will launch. And the name is the name of the script
found in /etc/init.d/. Things to be aware of is that order is important,
you don't want to try and start ntp (network time protocol) before the
network has been brought up, so ntp should have a higher number then
networking so that it starts later. The same process is used for killing
services, lower number is killed first, so you want to reverse the order
in our ntp example above. Now to actually get mysql to start up: Since
MySql relies on the network and portmap and that is all. On Debian
networking is found at /etc/rcS.d/S40networking and since this is run
before /etc/rc2.d/ then we can place mysql anywhere we like after
portmap starts. Portmap is at /etc/rc2.d/S18portmap, so lets put MySQL
at 20. Create a sym link for MySQL:

ln -s /etc/init.d/mysql /etc/rc2.d/S20mysql

Now MySQL will start on runlevel 2 just like if you typed
/etc/init.d/mysql start as root after booting. Now to cleanly stop MySQL
when you shut the computer down. Do the same thing, but use the KXXname
form in rc0.d and rc6.d directories. Be sure to stop MySQL before you
stop portmap and networking. I would create a symlink K20mysql in
/etc/rc0.d and /etc/rc6.d. Now every distro that I've worked with has a
tool to help manage these scripts and can make your life easier. The
default one in Debian is update-rc.d. All you do is specify the script
name and what levels you want to start it in and which to kill it in and
in what priority and it does all the linking for you.

That is the Reader's digest version. It is by no means complete and
there may be some flaws, but it should get you started in understanding
how runlevels are used in Linux.

Robert

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Jacob Albretsen
Sent: Friday, January 27, 2006 7:51 PM
To: UUG-Discuss
Subject: [uug] System Services

Thus begins my migration from Mandrivake.

In Mandrivake, drakconf has this nifty tool where you can tell your
system to 
start a service at boot.  For example, if you want to have mysql start
at 
boot, you just go in and check the box for it.  Done.

With Ubuntu, there is no nifty system services tool that I can see that
is 
native to Ubuntu.  I looked at the one in Gnome, and it seems super
dumbed 
down and doesn't have  1/3 of what I'm used to controlling and know
that's 
there.  I looked at the one in KDE and it has something, but one can 
configure it for each different run level.

Now, here is were my knowledge breaks down, run levels have always
seemed odd 
to me.  Other than single user, reboot, and multi-user, I don't see the
need 
to have more than three.  But then again, I'm not an expert at this, so
I'm 
sure there is a good reason.

I tried to use the KDE tool to turn off some things at boot like mysql,
but I 
noticed that all the services are available at every run level, and
mysql 
starts at boot on levels 2, 3, 4, and 5.  So.... if I want to stop mysql
from 
turning on at boot, must I edit every singe runlevel with this tool?
And if 
I want to start a service at boot, how do I know what levels to have it
turn 
on at boot and which ones not to? (other than init 6 of course) This
just 
seems odd to me, why would a service turn on four times at boot?  (I'm 
totally showing make lack of knowledge in this area)

I've done some Googling and found that each distro treats runlevels 
differently.  The doc I found said that Debian considers 2, 3, 4, and 5 
multi-user, thus causing me to be more confused.

So... perhaps someone can enlighten me on this subject or suggest a good
tool 
for the job?

Thanks.

--------------------
BYU Unix Users Group 
http://uug.byu.edu/ 

The opinions expressed in this message are the responsibility of their
author.  They are not endorsed by BYU, the BYU CS Department or BYU-UUG.

___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list


--------------------
BYU Unix Users Group
http://uug.byu.edu/

The opinions expressed in this message are the responsibility of their
author.  They are not endorsed by BYU, the BYU CS Department or BYU-UUG.
___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list

Reply via email to