The way Linux starts (and stops) all its subsystems is very simple and modular. Lets you define initialization order, runlevels etc
The default runlevel is defined in /etc/inittab with a line like this:
Example 3. Default runlevel (3, in this case) line in /etc/inittab
id:3:initdefault: |
Runlevels are numbers from 0 to 6 and each one of them is used following this standard:
bash# runlevel N 3 bash# telinit 5 bash# runlevel 3 5 bash# |
Subsystems are organized under the /etc/init.d and /etc/rc.d/rcN.d directories:
All installed Subsystems put in this directory a control program, which is a script that follows a simple standard described bellow. This is a simplified listing of this directory:
Example 4. Subsystems installed in /etc/init.d
bash:/etc/init.d# ls -l -rwxr-xr-x 1 root root 9284 Aug 13 2001 functions -rwxr-xr-x 1 root root 4984 Sep 5 00:18 halt -rwxr-xr-x 1 root root 5528 Nov 5 09:44 firewall -rwxr-xr-x 1 root root 1277 Sep 5 21:09 keytable -rwxr-xr-x 1 root root 487 Jan 30 2001 killall -rwxr-xr-x 1 root root 7958 Aug 15 17:20 network -rwxr-xr-x 1 root root 1490 Sep 5 07:54 ntpd -rwxr-xr-x 1 root root 2295 Jan 30 2001 rawdevices -rwxr-xr-x 1 root root 1830 Aug 31 09:29 httpd -rwxr-xr-x 1 root root 1311 Aug 15 14:18 syslog |
Example 5. /etc/rc3.d listing
bash:/etc/rc3.d# ls -l lrwxrwxrwx 1 root root 18 Jan 14 11:59 K92firewall -> ../init.d/firewall lrwxrwxrwx 1 root root 17 Jan 14 11:59 S10network -> ../init.d/network lrwxrwxrwx 1 root root 16 Jan 14 11:59 S12syslog -> ../init.d/syslog lrwxrwxrwx 1 root root 18 Jan 14 11:59 S17keytable -> ../init.d/keytable lrwxrwxrwx 1 root root 20 Jan 14 11:59 S56rawdevices -> ../init.d/rawdevices lrwxrwxrwx 1 root root 16 Jan 14 11:59 S56xinetd -> ../init.d/xinetd lrwxrwxrwx 1 root root 18 Jan 14 11:59 S75httpd -> ../init.d/httpd lrwxrwxrwx 1 root root 11 Jan 13 21:45 S99local -> ../rc.local |
Example 6. Skeleton of a Subsystem control program in /etc/init.d
bash# /etc/init.d/mysystem Usage: mysystem {start|stop|restart|reload|condrestart|status} |
The mysystem subsystem methods you implemented will be called by users with the service command like this example:
Example 7. service command usage
bash# service mysystem start Starting MySystem: [ OK ] bash# service mysystem status Subsysten MySystem is active with pid 1234 bash# service mysystem reload Reloading MySystem: [ OK ] bash# service mysystem stop Stopping MySystem: [ OK ] bash# |
Example 8. Using the chkconfig command
bash# chkconfig --add mysystem bash# chkconfig --del mysystem |
Read the chkconfig manual page to see what more it can do for you.