p .Nm rc.shutdown is the command script which shuts down various services, and is invoked by .Xr shutdown 8 as part of the process of shutting down the system.
p .Nm rc.d/ is the directory which contains various scripts, one for each service, which are called by .Nm at startup, .Nm rc.shutdown at shutdown, and as necessary during system operation to stop, start, restart, reload, (etc) the service. .Ss Operation of rc l -enum t Source
a /etc/rc.subr to load various shell functions to use. t If autobooting, set .Dv $autoboot to .Sq yes , and enable a flag which prevents the .Nm rc.d scripts from performing the check for already running processes (thus speeding up the boot process). This speedup won't occur when .Nm is started up after exiting the single-user shell. t Invoke .Xr rcorder 8 to order the files in
a /etc/rc.d/ that do not have a .Dq nostart keyword (refer to .Xr rcorder 8 's .Fl s flag), and assigns the result to a variable. t Calls each script in turn using run_rc_script() (from
a /etc/rc.subr ) , which sets .Dv $1 to .Sq start , and sources the script in a subshell. If the script has a .Sq .sh suffix then it is sourced directly into the current shell. .El .Ss Operation of rc.shutdown l -enum t Source
a /etc/rc.subr to load various shell functions to use. t Invoke .Xr rcorder 8 to order the files in
a /etc/rc.d/ that have a .Dq shutdown keyword (refer to .Xr rcorder 8 's .Fl k flag), reverses that order, and assigns the result to a variable. t Calls each script in turn using run_rc_script() (from
a /etc/rc.subr ) , which sets .Dv $1 to .Sq stop , and sources the script in a subshell. If the script has a .Sq .sh suffix then it is sourced directly into the current shell. .El .Ss Contents of rc.d/
p .Nm rc.d/ is located in
a /etc/rc.d . The following file naming conventions are currently used in .Nm rc.d/ : l -tag -width ALLUPPERCASE -offset indent t ALLUPPERCASE Scripts that are .Sq placeholders to ensure that certain operations are done before others, such as: l -tag -width SERVERS t DAEMON before all general purpose daemons t LOGIN before user login processes t NETWORK ensure basic network services are running t SERVERS ensure basic services exist for services that start early. .El t foo.sh Scripts that are to be sourced into the current shell rather than a subshell. Extreme care must be taken in using this, as the startup sequence will terminate if the script does.
a /etc/rc.d/bootconf.sh uses this behaviour to allow the user to select a different configuration (including
a /etc/rc.conf ) early in the boot. t bar Scripts that are sourced in a subshell. These can stop the boot if necessary with the following shell commands: d -literal -offset if [ "$autoboot" = yes ]; then kill -TERM $$ fi exit 1 .Ed
p Note that this should be used sparingly! .El
p The scripts are expected to support at least the following arguments: l -tag -width restart -offset indent t start Start the program. This should check that the program is to be started as specified by .Xr rc.conf 5 . If .Sq forcestart is given, ignore the rc.conf check and start anyway. t stop If the program is to be started as specified by .Xr rc.conf 5 , stop the program. This should check that the program is running and complain if it's not. If .Sq forcestop is given, ignore the rc.conf check and attempt to stop. t restart Effectively perform a stop then a start. t status Show the status of the program. Defaults to displaying the process ID of the process (if running). .El
p Other arguments (such as .Sq reload , .Sq dumpdb , etc) can be added if necessary.
p In order to simplify scripts, the run_rc_command() function from
a /etc/rc.subr may be used. .Sh FILES l -tag -width /etc/rc.shutdown -compact t Pa /etc/rc Startup script called by .Xr init 8 . t Pa /etc/rc.d/ Directory containing control scripts for each service. t Pa /etc/rc.shutdown Shutdown script called by .Xr shutdown 8 . t Pa /etc/rc.subr Contains functions used by various scripts. .El .Sh SEE ALSO .Xr rc.conf 5 , .Xr init 8 , .Xr rcorder 8 , .Xr reboot 8 , .Xr shutdown 8 .Sh HISTORY The .Nm command appeared in x 4.0 . The
a /etc/rc.d support was implemented in .Nx 1.5 by Luke Mewburn <lukem (at] netbsd.org>.