-   Linux - Software (
-   -   how does system-config-services know the correct order for service startup ? (

jtmoon 06-17-2006 12:50 AM

how does system-config-services know the correct order for service startup ?
Is it taken from a simple text file?
Is it hardcoded into the binary?
Is it from rand()?
Is it based on the position of Jupiter in relation to Saturn?

It's a small curiosity I for which I would like an answer.

Yes, this could also fit into the RedHat and Fedora forums.

-J Tom Moon

GrueMaster 06-17-2006 01:08 AM

Iff you look in /etc, you will find several subdirectories and configuration files. One of these directories contains the startup scripts for all of the system services (/etc/init.d). The order in which these scripts is executed is a semi-complex operation beginning within each one of these scripts. If you look at one of these scripts, near the top wil be a line as follows:

# chkconfig: 35 91 9

This is read by a script called "chkconfig". chkconfig can add a script to the runtime directories (/etc/rc[1-5].d) in the correct order of execution. If you look at /etc/rc5.d, you will notice several sympolic links that start with either an S or a K, followed by two numbers and the name of the service. When the init process is booting up, it first determines which runlevel to start in by reading the /etc/inittab file, then executing each script in order. The K, means to kill a service when entering this runlevel, an S means to start the service.

The numbers give each service an order of precidence. For example, you don't want your system running the file or web server services before the network has started. You also don't want the network to start before the system has had a chance to discover if there is a new network card or other hardware that needs configuring. Currently, each service waits for the previous service to finish initializing (pass or fail, they still wait). Work is currently under way for processes to be brought up in parallel, which would greatly spead up the Linux boot process. Things like the background virus scanning software (clamav) could be started while waiting for the network to retrieve an ip address, or the XWindows system could be started while wating for the print services to initialize.

paulsm4 06-17-2006 01:16 AM

Basically, the Linux kernel starts the "init" program (process ID "1"), "init" executes the stuff listed in "/etc/inittab" (depending on which "run level" states it passes through), and each "run level" invokes zero or more startup or shutdown scripts located in /etc/rc.d/rcX.d (where "X" is run level 0, 1, 2, 3, 4, 5 or 6). The scripts are run consecutively, in alphabetic order.

For example, these are the scripts run for "init 3" (run level 3 == multi-user, text mode):

  ls /etc/rc.d/rc3.d =>
K04powersaved      K12nfs          S01isdn          S12kbd
K05haldaemon      K12nfsboot      S01random        S12mysql
K06cron            K14mdnsd        S01resmgr        S12running-kernel
K06smbfs          K14portmap      S04boot.udev    S12splash
K07apache2        K14splash_early  S05network      S12sshd
K08nscd            K14vmware        S06dbus          S13cups
K08postfix        K15nmb          S06syslog        S14nscd
K08smb            K16dbus          S07nmb          S14postfix
K08xinetd          K16syslog        S08mdnsd        S14smb
K09cups            K17network      S08portmap      S14xinetd
K10acpid          K18boot.udev    S08splash_early  S15apache2
K10alsasound      K21fbset        S08vmware        S16cron
K10mysql          K21isdn          S10nfs          S16smbfs
K10running-kernel  K21random        S10nfsboot      S17haldaemon
K10splash          K21resmgr        S12acpid        S18powersaved
K10sshd            S01fbset        S12alsasound

Some of these scripts start daemons (for example, "mysqld"), others just do one-time setup ("S" for Start) or shutdown ("K" for Kill) activity.

Here's a link that explains further:

I was typing my (long-winded!) explanation at the same time as GrueMaster. We're both saying the same thing - apologies for any duplicate redundancy ;-)

All times are GMT -5. The time now is 01:54 PM.