Table of Contents
NetBSD uses individual scripts for controlling services, similar to what System V does, but without runlevels. This chapter is an overview of the rc.d system and its configuration.
The system startup files reside in the
directory. They are:
First, a look at controlling and supporting scripts (also documented in rc(8)).
After the kernel has initialized all devices at
startup, it starts init(8), which in turn runs
contains common functions used by
and various rc.d scripts.
When shutting down the system with shutdown(8),
/etc/rc.shutdown is run, which runs the
/etc/rc.d in reverse
order (as defined by rcorder(8)). Note that if you shut
down the system using the halt(8) command, these scripts
will not be run.
Additional scripts outside of the
/etc/rc.local is almost the last
script called at boot up. This script can be edited by the
administrator to start local daemons that don't fit the
rc.d scripts are controlled by a central configuration file,
/etc/rc.conf, which loads its default settings from
/etc/defaults/rc.conf. If you want to change a
default setting, do not edit
instead, override the setting in
It is a good idea to read the rc.conf(5) man page to learn about the services that are available to you.
The following example shows how to enable the SSH daemon, which is disabled by default:
cd /etc; grep ssh defaults/rc.confsshd=NO sshd_flags=""
echo "sshd=YES" >> rc.conf
Now sshd(8) will be started automatically at system startup. The next section describes how to start and stop services at any time.
Last but not least, files can be created in the
/etc/rc.conf.d/ directory to override the behavior
of a given rc.d script without editing the script itself.
The actual scripts that control services are in
/etc/rc.d. These scripts are automatically
run at boot time, but they can be called manually if necessary.
The following example shows how to start the SSH daemon
that we enabled in the previous section:
/etc/rc.d/sshd startStarting sshd.
Later, if you wish to stop the SSH daemon, run the following command:
/etc/rc.d/sshd stopStopping sshd. Waiting for PIDS: 123.
The rc.d scripts take one of the following arguments:
Some scripts may support other arguments (e.g., “reload”), but every script will support at least the above commands.
As an example, after adding a new record to a named(8) database, the daemon can be told to reload its configuration files with the following command:
/etc/rc.d/named reloadReloading named config files.
Note that all of the commands discussed above will only take action
if the particular service is enabled in
/etc/rc.conf. It is possible to bypass this
requirement by prepending “one” to the command, as in:
/etc/rc.d/httpd onestartStarting httpd.
The above command will allow you to start the httpd(8) service one time. To stop a service that has been started in this manner, pass “onestop” to the script.
Several packages install rc.d scripts. By default package
rc.d scripts can be found in
/usr/pkg/share/examples/rc.d and need to be
manually copied to
/etc/rc.d in order to
be used. Setting
environment variable prior installing packages enable automatic
copying rc.d scripts to
The startup system of every Unix system determines, in one way
or another, the order in which services are started. On some Unix
systems this is done by numbering the files and/or putting them in
separate run level directories. Solaris relies on wildcards like
/etc/rc.d/S* being sorted numerically when
expanded. Some simply put all the commands that should be started
into a single monolithic script (this is the traditional BSD method,
and is what NetBSD did before the rc.d system). On modern NetBSD this
is done by the rc.d scripts and their contents. Please note that NetBSD
does not use multiple runlevels.
At the beginning of each rc.d script there is a series of commented out lines that have one of the following items in them:
These describe the dependencies of that particular script and
allow rcorder to easily work either “up” or
“down” as the situation requires. As an example, here
is the ordering information contained in
... PROVIDE: nfsd REQUIRE: rpcbind mountd ...
Here we can see that this script provides the “nfsd” service and that it requires “rpcbind” and “mountd” to be running first. The rcorder(8) utility is used at system startup time to read through all the rc.d scripts and determine the order in which they should be run.
Luke Mewburn, one of the principal designers of the rc.d system, gave a presentation on the system at USENIX 2001. It is available in PDF format.