1: # The rc.d System
3: NetBSD uses individual scripts for controlling system and service startup,
4: similar to System V, but without runlevels.
5: Nowadays, most Linux distributions switched to systemd, which is a different
6: approach: It does not use scripts anymore, but tries to have everything binary.
7: It also serves for several other purposes, while NetBSD's rc.d system just
8: serves for starting up services at system startup or by user intervention.
10: This chapter is an overview of NetBSD's rc.d system and its configuration.
12: ## Basics
14: The system startup files reside in the `/etc` directory. They are:
16: * `/etc/rc`
17: * `/etc/rc.conf`
18: * `/etc/rc.d/*`
19: * `/etc/rc.lkm`
20: * `/etc/rc.local`
21: * `/etc/rc.shutdown`
22: * `/etc/rc.subr`
23: * `/etc/defaults/*`
24: * `/etc/rc.conf.d/*`
26: First, a look at controlling and supporting scripts (also documented in
29: * After the kernel has initialized all devices at startup, it starts
31: which in turn runs `/etc/rc`.
33: * `/etc/rc` sorts the scripts in `/etc/rc.d` using
35: and then runs them in that order. See below and the manpage for details of
36: how the order of rc.d scripts is determined.
38: * `/etc/rc.subr` contains common functions used by `/etc/rc` and various rc.d
41: * When shutting down the system with
43: `/etc/rc.shutdown` is run, which runs the scripts in `/etc/rc.d` in
44: reverse order (as defined by
47: *Note*: If you shut down the system using the
49: command, these scripts will not be run.
51: There are some special scripts outside the `rc.d` directory, which are also
54: * `/etc/rc.lkm` loads or unloads Loadable Kernel Modules (LKMs). See
56: and `/etc/rc.d/lkm`.
58: * `/etc/rc.local` is almost the last script called at boot up. This script can
59: be edited by the administrator to start local daemons that don't fit the
60: rc.d model, or do maintenance that should be done only once at startup.
62: rc.d scripts are controlled by a central configuration file, `/etc/rc.conf`,
63: which loads its default settings from `/etc/defaults/rc.conf`. If you want to
64: change a default setting, do not edit `/etc/defaults/rc.conf`; instead, override
65: the setting in `/etc/rc.conf`.
67: It is a good idea to read the
69: man page to learn about the services that are by default available to you.
71: The following example shows how to enable the SSH daemon, which is disabled by
74: # cd /etc; grep ssh defaults/rc.conf
75: sshd=NO sshd_flags=""
76: # echo "sshd=YES" >> rc.conf
78: Now [sshd(8)](http://netbsd.gw.com/cgi-bin/man-cgi?sshd+8+NetBSD-5.0.1+i386)
79: will be started automatically at system startup. The next section describes how
80: to start and stop services at any time.
82: Last but not least, files can be created in the `/etc/rc.conf.d/` directory to
83: override the behavior of a given rc.d script without editing the script itself.
85: ## The rc.d scripts
87: The actual scripts that control services are in `/etc/rc.d`. These scripts are
88: automatically run at boot time, but they can be called manually if necessary.
89: The following example shows how to start the SSH daemon that we enabled in the
90: previous section:
92: # /etc/rc.d/sshd start
93: Starting sshd.
95: Later, if you wish to stop the SSH daemon, run the following command:
97: # /etc/rc.d/sshd stop
98: Stopping sshd.
99: Waiting for PIDS: 123.
101: The rc.d scripts take one of the following arguments:
103: * `start`
104: * `stop`
105: * `restart`
106: * `status`
108: Some scripts may support other arguments (e.g., `reload`), but every script will
109: support at least the above commands.
111: As an example, after adding a new record to a
113: database, the daemon can be told to reload its configuration files with the
114: following command:
116: # /etc/rc.d/named reload
117: Reloading named config files.
119: Note that all of the commands discussed above will only take action if the
120: particular service is enabled in `/etc/rc.conf`. It is possible to bypass this
121: requirement by prepending `one` to the command, as in:
123: # /etc/rc.d/httpd start
124: $httpd is not enabled - see rc.conf(5).
125: Use the following if you wish to perform the operation:
126: /etc/rc.d/httpd onestart
127: # /etc/rc.d/httpd onestart
128: Starting httpd.
130: The above command will allow you to start the
132: service one time. To stop a service that has been started in this manner, pass
133: `onestop` to the script.
135: ## Order/dependencies of start determined by rcorder
137: The startup system of every Unix system determines, in one way or another, the
138: order in which services are started. On some Unix systems this is done by
139: numbering the files and/or putting them in separate run level directories.
140: Solaris relies on wildcards like `/etc/rc.d/S*` being sorted numerically
141: when expanded. Some simply put all the commands that should be started into a
142: single monolithic script (this is the traditional BSD method, and is what NetBSD
143: did before the rc.d system). On modern NetBSD this is done by the rc.d scripts
144: and their contents. Please note that NetBSD does not have multiple runlevels as
145: found in SysV-style systems like Solaris and Linux.
147: At the beginning of each rc.d script there is a series of commented out lines
148: that have one of the following items in them:
150: * `REQUIRE`
151: * `PROVIDE`
152: * `BEFORE`
153: * `KEYWORD`
155: These describe the dependencies of that particular script and allow rcorder to
156: easily work either `up` or `down` as the situation requires. As an example, here
157: is the ordering information contained in `/etc/rc.d/nfsd`:
160: # PROVIDE: nfsd
161: # REQUIRE: rpcbind mountd
164: Here we can see that this script provides the `nfsd` service and that it
165: requires `rpcbind` and `mountd` to be running first. The
167: utility is used at system startup time to read through all the rc.d scripts and
168: determine the order in which they should be run.
170: ## rc.d scripts of additional services
172: Packages you install additionally won't be listed in the rc.conf(5) manpage.
173: Packages installing services which can be started with an rc.d script tell you
174: so after they are installed, along with the variable that is used for starting
175: them (usually, it has the same name as the service itself).
177: Then, you usually have to copy them from `/usr/pkg/share/examples/rc.d` to
178: `/etc/rc.d` for `rc` to automatically find them, or add the line
180: rc_directories="/etc/rc.d /usr/pkg/share/examples/rc.d"
182: to your `/etc/rc.conf`.
184: If you forgot the name of the service variable, you can have a look at the rc.d
185: script itself. The variable `rcvar` (usually set to `$name`) will tell you.
186: E.g., to find the name of variable to start fscd, run
188: $ grep ^rcvar /etc/rc.d/fscd
190: $ grep ^name /etc/rc.d/fscd # Aaaw, no direct rcvar.
193: Thus, you need in your `/etc/rc.conf` the entry:
197: ## Additional Reading
199: Luke Mewburn, one of the principal designers of the rc.d system, gave a
200: presentation on the system at USENIX 2001. It is available in
201: [PDF](http://www.mewburn.net/luke/papers/rc.d.pdf) format.
CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb