2.3. Services and Runtime Control Scripts

Each runlevel is characterised by a set of services that are either started or stopped. The services are controlled by initialisation scripts (also called initscripts or rc-scripts).

According to the Linux Standard Base specification (LSB), these files are kept in /etc/init.d.

However this location may be a symbolic link to another directory. This is the case on RedHat based distributions which store the scripts in /etc/rc.d/init.d.

Each rc-script will control the daemon associated with the service using an argument.

Table 2.2. Expected rc-script arguments

restartdo stop the start
stopstop the daemon associated with the service
startstart the service
statusreturn the status of the services (running or stopped)

Figure 2.1. Typical services in /etc/init.d/

ls /etc/init.d/
anacron   gpm       kadmin   nfs       smb
apmd      halt      krb524   nfslock   squid
arpwatch  httpd     krb5kdc  nscd      sshd
atd       identd    ldap     ntpd      syslog
autofs    ipchains  lpd      pcmcia    xfs
crond     iptables  named    portmap   xinetd
dhcpd     irda      network  sendmail

Once a service is started it will run until a new runlevel is started.

2.3.1. Selecting Services per Runlevel

We will follow what happens when we switch from one runlevel to another.

Say you want to be in runlevel 2, you would type:

/sbin/init 2

This in turn forces init to read its configuration file /etc/inittab. We will look at this file in detail in the next section. For now we are concerned with the single line in /etc/inittab that will start all the services:

L2:2:wait:/etc/rc.d/rc 2

The /etc/rc.d/rc 2 command will start scripts in /etc/rc.d/rc2.d starting with an S and will stop of services starting with a K. The next sample listing shows that the httpd daemon will be stopped, while the syslogd daemon

ls /etc/rc.d/rc2.d/ -l | egrep "httpd|syslog"
 -- snip -- /etc/rc.d/rc2.d/K15httpd -> ../init.d/httpd
 -- snip -- /etc/rc.d/rc2.d/S12syslog -> ../init.d/syslog

Therefore, if you don't want a process to run in a given runlevel N you can delete the corresponding symlink in /etc/rc.d/rcN.d beginning with a K.

2.3.2. Shutting Down the System

Although it is possible to shutdown a system using init or telinit, it is recommanded to use the command shutdown.

A shutdown command will request init to change its runlevel. At first init notifies all the processes that are not associated with a runlevel that the system is going down. This gives programs time to properly save or close any opened files.

The notifications are sent using a SIGTERM signal and after 5 seconds these processes are sent a SIGKILL. The -t option to shutdown can be used to alter this delay.

One can also control fsck to either skip or force a filesystem check at the next system boot. The system startup script (e.g rc.sysinit) will look for a file at the root of each filesystem to determine which options to call fsck with.

The -F option to shutdown will create a file called /forcefsck forcing a fsck at the next boot. Similarly, the -f flag will create a file called /fastboot and the filesystem check is not forced.

2.3.3. Runtime Editors

Not an LPI objective

A runtime editor will automatically manage these symbolic links allowing a system administrator to switch a service on or off per runlevel as needed. Once again different distributions use different tools. Since the LPI certification is vendor independent none of these tools are examinable.