The heart of the SysV mechanism mentioned in the previous slide is a script called "/etc/init.d/rc" and a very clever directory structure full of symbolic links. All of the actual init scripts are locate in /etc/init.d/, but there are directories "/etc/rc0.d, /etc/rc1.d, ... /etc/rc6.d" that contain symbolic links to the scripts in /etc/init.d/. As you would guess the directory /etc/rc3.d has symlinks inside of it to the services that start and stop in runlevel 3. Using symlinks and the start, stop, reload, restart handlers in each script centralizes the logic for these init scripts and completely eliminates duplication... but there is another level of coolness to this scheme. For those of you who have been paying attention, you might wonder how a symlink alone could tell the SysV mechanism to start the webserver or stop it. That's where the "/etc/init.d/rc" script comes in. The symlinks in these /etc/rcX.d directories have names that start with an "S" or a "K". The rc script looks through these directories and anytime it finds a script symlink that starts with an "S" it runs that script with "start" as a parameter and when it finds a symlink that starts with a "K" it runs that script with "stop" as a parameter. For example, all of the symlinks in the /etc/rc0.d directory should start with a "K" because we are halting the system. (note: this is actually not true due to the fact that some services' only purpose is to prepare the machine for halting) If you thought that was all of the "cool" that this scheme had to deliver, then you are mistaken. The final blow is that these symlinks also have a number in the name (eg. S20acpid). This number determines the startup sequence of the service, so if one service depends on another service being started, then give the dependant a slightly higher number than the service it depends on. On top of that, there are defined stages of system startup are denoted by ranges of numbers, for example:
- After the S40 scripts have executed, all local file systems are mounted and networking is available. All device drivers have been initialized.
- After the S60 scripts have executed, the system clock has been set, NFS filesystems have been mounted (unless the system depends on the automounter, which is started later) and the filesystems have been cleaned.
![[logo]](logo.png)