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.
The rc files for the system reside under /etc, they are:
/etc/rc
/etc/rc.conf
/etc/rc.d/*
/etc/rc.lkm
/etc/rc.local
/etc/rc.shutdown
/etc/rc.subr
/etc/defaults/*
/etc/rc.conf.d/*
First, a look at controlling and supporting scripts:
/etc/rc runs the scripts in /etc/rc.d
/etc/rc.subr contains common functions used by rc scripts.
/etc/shutdown calls the scripts in /etc/rc.d in reverse order.
Additional scripts outside of the rc.d directory:
/etc/rc.lkm loads or unloads Loadable Kernel Modules.
/etc/rc.local almost the last script called at boot up, local daemons may be added here.
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.
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:
start
stop
restart
kill
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
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.
There are other resources available pertaining to the rc.d system:
One of the principal designers of rc.d, Luke Mewburn, gave a presentation on the system at USENIX 2001. It is available in PDF format.
Will Andrews wrote a Daemonnews article called The NetBSD rc.d System.