auto-starting daemons on startup

R Shapiro yellowdog-general@lists.terrasoftsolutions.com
Tue May 21 06:46:01 2002


Chaz writes:
 > 	I have a certain server that I would like to start automatically on 
 > startup, but I'm not sure how this is done.  I'm not much of a 
 > Linux-head.  I don't know much about inetd or xinetd or really how 
 > services work.  Can somebody please explain the process?

As someone else already pointed out, there's a very good chance that
whatever you think you have to add has already been provided for.  So
you should tell us what you're planning to do here.  It's silly, and
imo wrong, to add new init entries (or, worse, add things to rc.local)
if whatever you want to do has already been provided for elsewhere.

Having said that, I'll describe the process in some detail.

The general mechanism in YDL and other Redhat deriviatves for running
arbitary scripts at special system times (eg boot and shutdown) is the
idea of runlevels. The best way to understand how this works is to
look at /etc/inittab and the shell script /etc/rc.d/rc.  The actions
associated with each runlevel are defined in /etc/inittab.  The core
of it is an invocation of the the script /etc/rc.d/rc with the level
as argument.  The rest of this post describes how the /etc/rc.d/rc
script works.

In /etc/rc.d, you'll notice a set of directories with names like
rc1.d, rc2.d, ..., rc6.d.  These directories define most of what
happens when the system enters the corresponding runlevel.  By
convention the entries in the various /etc/rc.d/rcX.d directories are
links to scripts that actually live in /etc/rc.d/init.d.

The file names in these rcX.d directories have a very standardized
format.  The first letter is either K or S, followed by a two digit
number, followed by an arbitrary name.  The name is an identifier for
the subsystem, which will be used to determine whether or not it's
currently running.  The digits are used to ensure that subsystems are
started or stopped in the right order.  The K/S determines whether the
subsystem should be killed when the sytem enters the given runlevel
(if it's currently running) or started when the system enters the
given runlevel (if it's not currently running).  A subsystem is killed
by invoking the script with the argument 'stop'.  A subsystem is
started by invoking the script with the argument 'start'.  A subsystem
is 'running', from the runlevel point of view, if a file with the name
/var/lock/subsys/$SUB or /var/local/sybsys/$SUB.init exists, where SUB
is the name portion of rcX.d entry.

Three runlevels are special: 0 for halt, 1 for single-user boot, 6 for
reboot.  The default boot runlevel is determined by a line in inittab,
which you can override by including the digit as kernel boot
parameter.  The normal boot runlevel is almost always either 3 or 5.
These generally have the same entries in their rcX.d directories (ie
they start/stop all the same subsystems) but 5 has an extra line in
/etc/inittab that also runs the graphic login screen.  There are
probably conventional uses for runlevels 2 and 4, but I don't know
what they are.  I configured runlevel 2 to run everything except the
network-related subsystems and 4 to run everything except nfs.  You
can also define runlevels 7-9 but I don't know anyone who does so.


That should be all you need to know if you really need to add new
things of your own devising to happen at boot time.  But, to repeat,
you shouldn't do this unless you have to.  It really is very likely
that whatever you want to do has already been provided for somewhere
else. 




-- 
rshapiro@bbn.com