Chapter 22 rc.d System

Table of Contents
22.1 The rc.d Configuration
22.2 The rc.d Scripts
22.3 The Role of rcorder and rc Scripts
22.4 Additional Reading

As of NetBSD version 1.5 the startup of the system changed slightly to using rc scripts for controlling services. This chapter is an overview of the rc configuration on NetBSD 1.5 and later.

22.1 The rc.d Configuration

The rc files for the system reside under /etc, they are:

First, a look at controlling and supporting scripts:

Additional scripts outside of the rc.d directory:

Following is the example from the system for an apache web server added to /etc/rc.local:

if [ -f /usr/pkg/etc/rc.d/apache ]; then
        /usr/pkg/etc/rc.d/apache start
fi

The /etc/defaults directory contains the default settings for NetBSD and the contents should not be changed. Within the rc context the only file of interest is rc.conf, this is the default rc configuration that ships with NetBSD. In order to alter a default setting, an override may be installed in /etc/rc.conf. For example, if you wanted to enable the Secure Shell Daemon:

# cd /etc; grep ssh defaults/rc.conf
sshd=NO                 sshd_flags=""
# echo "sshd=YES" >> rc.conf

Or just edit the file with your favorite editor. The same can be done with any default that needs to be changed.

Another way to make rc.conf easy to edit is to do the following:

# cd /etc/defaults
# cat rc.conf >> ../rc.conf

Then modify anything you need to.

Last and not least, the /etc/rc.conf.d/ directory can be used for scripts that are third party.

22.2 The rc.d Scripts

The actual scripts that control services are in /etc/rc.d. Once a service has been activated or told not to activate in /etc/rc.conf it can be also be modified by calling the rc script from the command line, for example if an administrator needed to start secure shell:

# /etc/rc.d/sshd start
Starting sshd.

The rc scripts must receive one of the following arguments:

An example might be when a new record has been added to the named database on a named server:

# /etc/rc.d/named restart
Stopping named.
Starting named.

A slightly more complex example is when a series of settings have been changed, for instance a firewall's ipfilter rules, ipnat configuration, and the secure shell server has switched encryption type:

# cd /etc/rc.d
# ./ipfilter restart; ./ipnat restart; ./sshd restart

22.3 The Role of rcorder and rc Scripts

As per the System Manager's Manual, rcorder is designed to print out a dependancy ordering of a set of interdependent files. It basically determines the order of execution one way or another. On some Unix systems this is done by numbering the files and/or putting them in separate run level directories. Which can be messy. On NetBSD this is done by the controlling scripts mentioned at the beginning of this document and by the contents of each rc script.

In the rc scripts there is a series of lines that have one of the following in them:

REQUIRE
PROVIDE
BEFORE
KEYWORD

These dicatate the dependencies of that particular rc script and hence rcorder can easily work either "up" or "down" as the situation requires. Following is an example of the nfsd rc script:

...
 PROVIDE: nfsd
 REQUIRE: mountd
. /etc/rc.subr
...

Here we can see that this script provides the nfsd service, however, it requires mountd to be running.

22.4 Additional Reading

There are other resources available pertaining to the rc.d system: