You can control which scripts are executed and the order in which they are executed by directly changing the logical links in the runlevel directory, but that's not the best way. It's easier to control startup scripts using a tool specifically designed for this purpose. Red Hat systems use the chkconfig command, which is a command-line tool based on the chkconfig program from the Silicon Graphics IRIX version of Unix. The Linux version has some enhancements, such as the capability to control which runlevels the scripts run under. The —list option of the chkconfig command displays the current settings:
[root]# chkconfig —list named named 0:off 1:off 2:off 3:on 4:on 5:on 6:off
This example shows the structure of a chkconfig command line. chkconfig is the command, —list is the option, and named is the name of a script file found in the init.d directory. It is the script file that the command affects.
To enable or disable a script for a specific runlevel, specify the runlevel with the —level option, followed by the name of the script you wish to control and the action you wish to take, either on to enable the script or off to disable it. For example, to disable named for runlevel 5, enter the following:
[root]# chkconfig —level 5 named off [root]# chkconfig —list named named 0:off 1:off 2:off 3:on 4:on 5:off 6:off chkconfig reads the comments in the init.d script file to determine the runlevels in which the script is run by default, and to obtain information needed to create the correct logical links in the runlevel directory. This information must be found in the script file in a comment that contains the keyword chkconfig. Here is an example from the ipchains script:
[root]# grep chkconfig ipchains
# chkconfig: 2345 08 92
In this comment, the keyword chkconfig is followed by three values:
• First, the list of runlevels in which this script is run by default. Here, the list contains four runlevels (2, 3, 4, and 5). If the script is not run by default at any runlevel, this field contains a dash (-).
• Next, the numeric prefix used to name the logical link to the script file used during startup. Here, the numeric prefix used for startup is 08. Therefore, the link placed in the runlevel directory will be named S08ipchains.
• Finally, the numeric prefix used to name the logical link to the script file used during shutdown. Here, the numeric prefix used for shutdown is 92. Therefore, the link placed in the runlevel directory will be named K92ipchains.
Editing the chkconfig comment in the script in the init.d directory changes the values that chkconfig uses to create the links. However, this is not necessary. The values selected by Red Hat were chosen to ensure that services start in the proper order. The only time you may need to set these values is when you write your own startup script for a custom service.
chkconfig is used on Red Hat and several other Linux systems. It is not, however, the only widely used tool for controlling scripts. tksysv, the SYSV Runlevel Manager, is available on several distributions; and it runs under X Windows. Figure 1.2 shows the SYSV Runlevel Manager window.
Figure 1.2: The SYSV Runlevel Manager Window
The SYSV Runlevel Manager lists all of the available startup scripts, as well as the scripts that are currently being used by each runlevel. Each runlevel has a column of the display that is divided into Start and Stop scripts. These categories correspond to the S and K scripts in the directories. Using tksysv's simple visual interface, you can add scripts to a runlevel from the list of available scripts, or delete scripts from a runlevel. You can even select a script from the list of available scripts and execute it in real time to start a service without rebooting.
Was this article helpful?