DragonFly On-Line Manual Pages
    
    
	
RC(8)                  DragonFly System Manager's Manual                 RC(8)
NAME
     rc - command scripts for auto-reboot and daemon startup
SYNOPSIS
     rc
     rc.conf
     rc.conf.local
     rc.d/
     rc.local.d/
     rc.firewall
     rc.local
     rc.shutdown
     rc.shutdown.local
     rc.subr
DESCRIPTION
     The rc utility is the command script which controls the automatic boot
     process after being called by init(8).  The rc.local and
     rc.shutdown.local scripts contains commands which are pertinent only to a
     specific site.  Typically, scripts in /usr/local/etc/rc.d/ is used
     instead of rc.local and rc.shutdown.local these days but if you want to
     use them it is still supported.  In this case, they should source
     /etc/rc.conf and contain additional custom startup and shutdown code for
     your system.  The best way to handle rc.local and rc.shutdown.local,
     however, is to separate them out into rc.d/ style scripts and place them
     under /usr/local/etc/rc.d/.  The rc.conf file contains the global system
     configuration information referenced by the startup scripts, while
     rc.conf.local contains the local system configuration.  See rc.conf(5)
     for more information.
     The rc.d/ directories contain scripts which will be automatically
     executed at boot time and shutdown time.  This directory is typically
     maintained by the system.  rc.local.d/ directories contain scripts which
     will be automatically executed at boot time and shutdown time.  This
     directory is typically maintained by the sysadmin.
   Operation of rc
     1.   Source /etc/rc.subr to load various rc.subr(8) shell functions to
          use.
     2.   If autobooting, set autoboot=yes and enable a flag (rc_fast=yes),
          which prevents the rc.d/ scripts from performing the check for
          already running processes (thus speeding up the boot process).  This
          rc_fast=yes speedup will not occur when rc is started up after
          exiting the single-user shell.
     3.   If the file /firstboot does not exist, add "firstboot" to the list
          of KEYWORDS to skip in rcorder(8).
     4.   Invoke rcorder(8) to order the files in /etc/rc.d/ and
          /etc/rc.local.d/ that do not have a "nostart" keyword (refer to
          rcorder(8)'s -s flag), and assign the result to a variable.
     5.   Call each script in turn using run_rc_script() (from rc.subr(8)),
          which sets $1 to "start", and sources the script in a subshell.  If
          the script has a .sh suffix then it is sourced directly into the
          current shell.
     6.   If the file /firstboot exists, delete it.
   Operation of rc.shutdown
     1.   Source /etc/rc.subr to load various rc.subr(8) shell functions to
          use.
     2.   Invoke rcorder(8) to order the files in /etc/rc.d/ and
          /etc/rc.local.d/ that have a "shutdown" keyword (refer to
          rcorder(8)'s -k flag), reverse that order, and assign the result to
          a variable.
     3.   Call each script in turn using run_rc_script() (from rc.subr(8)),
          which sets $1 to "stop", and sources the script in a subshell.  If
          the script has a .sh suffix then it is sourced directly into the
          current shell.
   Contents of rc.d/
     rc.d/ is located in /etc/rc.d/.  The following file naming conventions
     are currently used in rc.d/:
           ALLUPPERCASE      Scripts that are "placeholders" to ensure that
                             certain operations are performed before others.
                             In order of startup, these are:
                             FILESYSTEMS      Ensure that root and other
                                              critical local file systems are
                                              mounted.
                             NETWORKING       Ensure basic network services
                                              are running, including general
                                              network configuration (netif,
                                              routing, network_ipv6, ppp).
                             SERVERS          Ensure basic services (such as
                                              syslogd) exist for services that
                                              start early (such as named),
                                              because they are required by
                                              DAEMON below.
                             DAEMON           Check-point before all general
                                              purpose daemons such as dntpd
                                              and lpd.
                             LOGIN            Check-point before user login
                                              services (inetd and sshd), as
                                              well as services which might run
                                              commands as users (cron, jail
                                              and sendmail).
           foo.sh            Scripts that are to be sourced into the current
                             shell rather than a subshell have a .sh suffix.
                             Extreme care must be taken in using this, as the
                             startup sequence will terminate if the script
                             terminates.
           bar               Scripts that are sourced in a subshell.  These
                             can stop the boot if necessary with the following
                             shell commands:
                                   if [ "$autoboot" = yes ]; then
                                           kill -TERM $$
                                   fi
                                   exit 1
                             Note that this should be used extremely
                             sparingly!
     Each script should contain rcorder(8) keywords, especially an appropriate
     "PROVIDE" entry, and if necessary "REQUIRE" and "BEFORE" keywords.
     Each script is expected to support at least the following arguments,
     which are automatically supported if it uses the run_rc_command()
     function:
           start        Start the service.  This should check that the service
                        is to be started as specified by rc.conf(5).  Also
                        checks if the service is already running and refuses
                        to start if it is.  This latter check is not performed
                        by standard DragonFly scripts if the system is
                        starting directly to multi-user mode, to speed up the
                        boot process.  If faststart is given, skip the PID
                        check.  If forcestart is given, ignore the rc.conf(5)
                        check and start anyway.
           stop         If the service is to be started as specified by
                        rc.conf(5), stop the service.  This should check that
                        the service is running and complain if it is not.  If
                        forcestop is given, ignore the rc.conf(5) check and
                        attempt to stop.
           restart      Perform a stop then a start.
           reload       Send $sig_reload (defaults to HUP) to the program(s)
                        associated with the service.  Note that not all
                        scripts enable the reload command.
           status       If the script starts a process (rather than performing
                        a one-off operation), show the status of the process.
                        Otherwise it is not necessary to support this
                        argument.  Defaults to displaying the process ID of
                        the program (if running).
           poll         If the script starts a process (rather than performing
                        a one-off operation), wait for the command to exit.
                        Otherwise it is not necessary to support this
                        argument.
           rcvar        Display which rc.conf(5) variables are used to control
                        the startup of the service (if any).
     If a script must implement additional commands it can list them in the
     extra_commands variable, and define their actions in a variable
     constructed from the command name (see the EXAMPLES section).
     The following key points apply to old-style scripts in
     /usr/local/etc/rc.d/:
     *   Scripts are only executed if their basename(1) matches the shell
         globbing pattern *.sh, and they are executable.  Any other files or
         directories present within the directory are silently ignored.
     *   When a script is executed at boot time, it is passed the string
         "start" as its only argument.  At shutdown time, it is passed the
         string "stop" as its only argument.  All rc.d/ scripts are expected
         to handle these arguments appropriately.  If no action needs to be
         taken at a given time (either boot time or shutdown time), the script
         should exit successfully and without producing an error message.
     *   The scripts within each directory are executed in lexicographical
         order.  If a specific order is required, numbers may be used as a
         prefix to the existing filenames, so for example 100.foo would be
         executed before 200.bar; without the numeric prefixes the opposite
         would be true.
     *   The output from each script is traditionally a space character,
         followed by the name of the software package being started or shut
         down, without a trailing newline character (see the EXAMPLES
         section).
SCRIPTS OF INTEREST
     When an automatic reboot is in progress, rc is invoked with the argument
     autoboot.  One of the scripts run from /etc/rc.d/ is /etc/rc.d/fsck.
     This script runs fsck(8) with option -p to "preen" all UFS(5) file
     systems of minor inconsistencies resulting from the last system shutdown.
     If preening fails further action depends on the rc.conf(5) variable
     fsck_y_enable: if the value is "NO" (default) rc exits, if value is
     "YES", fsck(8) is run with option -y, if this also fails rc exits.  If
     autoboot is not set, when going from single-user to multi-user mode for
     example, the script does not do anything.
     The /etc/rc.d/localdaemons script can execute scripts from multiple rc.d/
     directories.  The default locations are /usr/local/etc/rc.d/ and
     /usr/pkg/etc/rc.d/, but these may be overridden with the local_startup
     rc.conf(5) variable.
     The /etc/rc.d/serial script is used to set any special configurations for
     serial devices.
     The /etc/rc.d/{net*,routing} scripts are used to start the network.  The
     network is started in several passes.  The first pass, /etc/rc.d/netif,
     configures the network interfaces.  The /etc/rc.d/routing script starts
     routing and sets routing options.  The /etc/rc.d/netoptions script sets
     additional networking options.  Finally, the /etc/rc.d/network_ipv6
     script configures IPv6 interfaces and options.
     The rc.firewall script is used to configure rules for the ipfw(4) kernel
     based firewall service.  It has several possible options:
           open          will allow anyone in
           client        will try to protect just this machine
           simple        will try to protect a whole network
           closed        totally disables IP services except via lo0 interface
           UNKNOWN       disables the loading of firewall rules
           filename      will load the rules in the given filename (full path
                         required).
     Most daemons, including network related daemons, have their own script in
     /etc/rc.d/, which can be used to start, stop, and check the status of the
     service.
     Any architecture specific scripts, such as specifically check that they
     are on that architecture before starting the daemon.
     Following tradition, all startup files reside in /etc.
FILES
     /etc/rc
     /etc/rc.conf
     /etc/rc.conf.local
     /etc/rc.d/
     /etc/rc.firewall
     /etc/rc.local
     /etc/rc.shutdown
     /etc/rc.shutdown.local
     /etc/rc.subr
EXAMPLES
     The following is a minimal rc.d/ style script.  Most scripts require
     little more than the following.
           #!/bin/sh
           #
           # PROVIDE: foo
           # REQUIRE: bar_service_required_to_precede_foo
           # BEFORE:  baz_service_requiring_foo_to_precede_it
           . /etc/rc.subr
           name="foo"
           rcvar=`set_rcvar`
           command="/usr/local/bin/foo"
           load_rc_config $name
           run_rc_command "$1"
     Certain scripts may want to provide enhanced functionality.  The user may
     access this functionality through additional commands.  The script may
     list and define as many commands at it needs.
           #!/bin/sh
           #
           # PROVIDE: foo
           # REQUIRE: bar_service_required_to_precede_foo
           # BEFORE:  baz_service_requiring_foo_to_precede_it
           . /etc/rc.subr
           name="foo"
           rcvar=`set_rcvar`
           command="/usr/local/bin/foo"
           extra_commands="nop hello"
           hello_cmd="echo Hello World."
           nop_cmd="do_nop"
           do_nop()
           {
                   echo "I do nothing."
           }
           load_rc_config $name
           run_rc_command "$1"
     The following is a simple, hypothetical example of an old-style
     /usr/local/etc/rc.d/ script, which would start a daemon at boot time, and
     kill it at shutdown time.
           #!/bin/sh -
           #
           #    initialization/shutdown script for foobar package
           case "$1" in
           start)
                   /usr/local/sbin/foo -d && echo -n ' foo'
                   ;;
           stop)
                   kill `cat /var/run/foo.pid` && echo -n ' foo'
                   ;;
           *)
                   echo "unknown option: $1 - should be 'start' or 'stop'" >&2
                   ;;
           esac
     As all processes are killed by init(8) at shutdown, the explicit kill(1)
     is unnecessary, but is often included.
SEE ALSO
     kill(1), ipfw(4), rc.conf(5), init(8), rcorder(8), rcrun(8), rc.subr(8),
     reboot(8), savecore(8)
HISTORY
     The rc utility appeared in 4.0BSD.  The rc.d/ facility was implemented in
     NetBSD 1.5 and appeared in DragonFly 1.0.
DragonFly 6.5-DEVELOPMENT      February 22, 2024     DragonFly 6.5-DEVELOPMENT