Diff for /wikisrc/guide/rc.mdwn between versions 1.2 and 1.3

version 1.2, 2013/03/01 16:49:18 version 1.3, 2013/03/05 23:33:53
Line 1 Line 1
 # The rc.d System  # The rc.d System
   
 NetBSD uses individual scripts for controlling system and service startup,   NetBSD uses individual scripts for controlling system and service startup,
 similar to System V, but without runlevels.  similar to System V, but without runlevels.
 Nowadays, most Linux distributions switched to systemd, which is a different   Nowadays, most Linux distributions switched to systemd, which is a different
 approach: It does not use scripts anymore, but tries to have everything binary.   approach: It does not use scripts anymore, but tries to have everything binary.
 It also serves for several other purposes, while NetBSD's rc.d system just   It also serves for several other purposes, while NetBSD's rc.d system just
 serves for starting up services at system startup or by user intervention.  serves for starting up services at system startup or by user intervention.
   
 This chapter is an overview of NetBSD's rc.d system and its configuration.  This chapter is an overview of NetBSD's rc.d system and its configuration.
Line 23  The system startup files reside in the ` Line 23  The system startup files reside in the `
  * `/etc/defaults/*`   * `/etc/defaults/*`
  * `/etc/rc.conf.d/*`   * `/etc/rc.conf.d/*`
   
 First, a look at controlling and supporting scripts (also documented in   First, a look at controlling and supporting scripts (also documented in
 [rc(8)](http://netbsd.gw.com/cgi-bin/man-cgi?rc+8+NetBSD-5.0.1+i386)):  [rc(8)](http://netbsd.gw.com/cgi-bin/man-cgi?rc+8+NetBSD-5.0.1+i386)):
   
  * After the kernel has initialized all devices at startup, it starts    * After the kernel has initialized all devices at startup, it starts
    [init(8)](http://netbsd.gw.com/cgi-bin/man-cgi?init+8+NetBSD-5.0.1+i386),     [init(8)](http://netbsd.gw.com/cgi-bin/man-cgi?init+8+NetBSD-5.0.1+i386),
    which in turn runs `/etc/rc`.     which in turn runs `/etc/rc`.
  * `/etc/rc` sorts the scripts in `/etc/rc.d` using   
    [rcorder(8)](http://netbsd.gw.com/cgi-bin/man-cgi?rcorder+8+NetBSD-5.0.1+i386)    * `/etc/rc` sorts the scripts in `/etc/rc.d` using
      [rcorder(8)](http://netbsd.gw.com/cgi-bin/man-cgi?rcorder+8+NetBSD-5.0.1+i386)
    and then runs them in that order. See below and the manpage for details of     and then runs them in that order. See below and the manpage for details of
    how the order of rc.d scripts is determined.     how the order of rc.d scripts is determined.
  * `/etc/rc.subr` contains common functions used by `/etc/rc` and various rc.d   
    * `/etc/rc.subr` contains common functions used by `/etc/rc` and various rc.d
    scripts.     scripts.
  * When shutting down the system with   
    [shutdown(8)](http://netbsd.gw.com/cgi-bin/man-cgi?shutdown+8+NetBSD-5.0.1+i386),    * When shutting down the system with
      [shutdown(8)](http://netbsd.gw.com/cgi-bin/man-cgi?shutdown+8+NetBSD-5.0.1+i386),
    `/etc/rc.shutdown` is run, which runs the scripts in `/etc/rc.d` in     `/etc/rc.shutdown` is run, which runs the scripts in `/etc/rc.d` in
    reverse order (as defined by      reverse order (as defined by
    [rcorder(8)](http://netbsd.gw.com/cgi-bin/man-cgi?rcorder+8+NetBSD-5.0.1+i386)).       [rcorder(8)](http://netbsd.gw.com/cgi-bin/man-cgi?rcorder+8+NetBSD-5.0.1+i386)).
    *Note*: If you shut down the system using the   
    [halt(8)](http://netbsd.gw.com/cgi-bin/man-cgi?halt+8+NetBSD-5.0.1+i386)      *Note*: If you shut down the system using the
      [halt(8)](http://netbsd.gw.com/cgi-bin/man-cgi?halt+8+NetBSD-5.0.1+i386)
    command, these scripts will not be run.     command, these scripts will not be run.
   
 There are some special scripts outside the `rc.d` directory, which are also  There are some special scripts outside the `rc.d` directory, which are also
 run:  run:
   
  * `/etc/rc.lkm` loads or unloads Loadable Kernel Modules (LKMs). See    * `/etc/rc.lkm` loads or unloads Loadable Kernel Modules (LKMs). See
    [modload(8)](http://netbsd.gw.com/cgi-bin/man-cgi?modload+8+NetBSD-5.0.1+i386)      [modload(8)](http://netbsd.gw.com/cgi-bin/man-cgi?modload+8+NetBSD-5.0.1+i386)
    and `/etc/rc.d/lkm[123]`.     and `/etc/rc.d/lkm[123]`.
  * `/etc/rc.local` is almost the last script called at boot up. This script can   
    * `/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     be edited by the administrator to start local daemons that don't fit the
    rc.d model, or do maintenance that should be done only once at startup.     rc.d model, or do maintenance that should be done only once at startup.
   
 rc.d scripts are controlled by a central configuration file, `/etc/rc.conf`,   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   which loads its default settings from `/etc/defaults/rc.conf`. If you want to
 change a default setting, do not edit `/etc/defaults/rc.conf`; instead, override   change a default setting, do not edit `/etc/defaults/rc.conf`; instead, override
 the setting in `/etc/rc.conf`.  the setting in `/etc/rc.conf`.
   
 It is a good idea to read the   It is a good idea to read the
 [rc.conf(5)](http://netbsd.gw.com/cgi-bin/man-cgi?rc.conf+5+NetBSD-5.0.1+i386)   [rc.conf(5)](http://netbsd.gw.com/cgi-bin/man-cgi?rc.conf+5+NetBSD-5.0.1+i386)
 man page to learn about the services that are by default available to you.  man page to learn about the services that are by default available to you.
   
 The following example shows how to enable the SSH daemon, which is disabled by   The following example shows how to enable the SSH daemon, which is disabled by
 default:  default:
   
     # cd /etc; grep ssh defaults/rc.conf      # cd /etc; grep ssh defaults/rc.conf
     sshd=NO                 sshd_flags=""      sshd=NO                 sshd_flags=""
     # echo "sshd=YES" >> rc.conf      # echo "sshd=YES" >> rc.conf
   
 Now [sshd(8)](http://netbsd.gw.com/cgi-bin/man-cgi?sshd+8+NetBSD-5.0.1+i386)   Now [sshd(8)](http://netbsd.gw.com/cgi-bin/man-cgi?sshd+8+NetBSD-5.0.1+i386)
 will be started automatically at system startup. The next section describes how   will be started automatically at system startup. The next section describes how
 to start and stop services at any time.  to start and stop services at any time.
   
 Last but not least, files can be created in the `/etc/rc.conf.d/` directory to   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.  override the behavior of a given rc.d script without editing the script itself.
   
 ## The rc.d scripts  ## The rc.d scripts
   
 The actual scripts that control services are in `/etc/rc.d`. These scripts are   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.   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   The following example shows how to start the SSH daemon that we enabled in the
 previous section:  previous section:
   
     # /etc/rc.d/sshd start      # /etc/rc.d/sshd start
Line 100  The rc.d scripts take one of the followi Line 105  The rc.d scripts take one of the followi
  * `restart`   * `restart`
  * `status`   * `status`
   
 Some scripts may support other arguments (e.g., `reload`), but every script will   Some scripts may support other arguments (e.g., `reload`), but every script will
 support at least the above commands.  support at least the above commands.
   
 As an example, after adding a new record to a   As an example, after adding a new record to a
 [named(8)](http://netbsd.gw.com/cgi-bin/man-cgi?named+8+NetBSD-5.0.1+i386)   [named(8)](http://netbsd.gw.com/cgi-bin/man-cgi?named+8+NetBSD-5.0.1+i386)
 database, the daemon can be told to reload its configuration files with the   database, the daemon can be told to reload its configuration files with the
 following command:  following command:
   
     # /etc/rc.d/named reload      # /etc/rc.d/named reload
     Reloading named config files.      Reloading named config files.
   
 Note that all of the commands discussed above will only take action if the   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   particular service is enabled in `/etc/rc.conf`. It is possible to bypass this
 requirement by prepending `one` to the command, as in:  requirement by prepending `one` to the command, as in:
   
     # /etc/rc.d/httpd start      # /etc/rc.d/httpd start
Line 122  requirement by prepending `one` to the c Line 127  requirement by prepending `one` to the c
     # /etc/rc.d/httpd onestart      # /etc/rc.d/httpd onestart
     Starting httpd.      Starting httpd.
   
 The above command will allow you to start the   The above command will allow you to start the
 [httpd(8)](http://netbsd.gw.com/cgi-bin/man-cgi?httpd+8+NetBSD-5.0.1+i386)   [httpd(8)](http://netbsd.gw.com/cgi-bin/man-cgi?httpd+8+NetBSD-5.0.1+i386)
 service one time. To stop a service that has been started in this manner, pass   service one time. To stop a service that has been started in this manner, pass
 `onestop` to the script.  `onestop` to the script.
   
 ## Order/dependencies of start determined by rcorder  ## Order/dependencies of start determined by rcorder
   
 The startup system of every Unix system determines, in one way or another, the   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   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.   numbering the files and/or putting them in separate run level directories.
 Solaris relies on wildcards like `/etc/rc[23].d/S*` being sorted numerically   Solaris relies on wildcards like `/etc/rc[23].d/S*` being sorted numerically
 when expanded. Some simply put all the commands that should be started into a   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   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   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 have multiple runlevels as   and their contents. Please note that NetBSD does not have multiple runlevels as
 found in SysV-style systems like Solaris and Linux.  found in SysV-style systems like Solaris and Linux.
   
 At the beginning of each rc.d script there is a series of commented out lines   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:  that have one of the following items in them:
   
  * `REQUIRE`   * `REQUIRE`
Line 147  that have one of the following items in  Line 152  that have one of the following items in 
  * `BEFORE`   * `BEFORE`
  * `KEYWORD`   * `KEYWORD`
   
 These describe the dependencies of that particular script and allow rcorder to   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   easily work either `up` or `down` as the situation requires. As an example, here
 is the ordering information contained in `/etc/rc.d/nfsd`:  is the ordering information contained in `/etc/rc.d/nfsd`:
   
     ...      ...
Line 156  is the ordering information contained in Line 161  is the ordering information contained in
     # REQUIRE: rpcbind mountd      # REQUIRE: rpcbind mountd
     ...      ...
   
 Here we can see that this script provides the `nfsd` service and that it   Here we can see that this script provides the `nfsd` service and that it
 requires `rpcbind` and `mountd` to be running first. The   requires `rpcbind` and `mountd` to be running first. The
 [rcorder(8)](http://netbsd.gw.com/cgi-bin/man-cgi?rcorder+8+NetBSD-5.0.1+i386)   [rcorder(8)](http://netbsd.gw.com/cgi-bin/man-cgi?rcorder+8+NetBSD-5.0.1+i386)
 utility is used at system startup time to read through all the rc.d scripts and   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.  determine the order in which they should be run.
   
 ## rc.d scripts of additional services  ## rc.d scripts of additional services
Line 191  Thus, you need in your `/etc/rc.conf` th Line 196  Thus, you need in your `/etc/rc.conf` th
   
 ## Additional Reading  ## Additional Reading
   
 Luke Mewburn, one of the principal designers of the rc.d system, gave a   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   presentation on the system at USENIX 2001. It is available in
 [PDF](http://www.mewburn.net/luke/papers/rc.d.pdf) format.  [PDF](http://www.mewburn.net/luke/papers/rc.d.pdf) format.
   

Removed from v.1.2  
changed lines
  Added in v.1.3


CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb