rc(8) | command scripts for auto-reboot and daemon startup |
rc.atm, rc(8) | command scripts for auto-reboot and daemon startup |
rc.d, rc(8) | command scripts for auto-reboot and daemon startup |
rc.firewall, rc(8) | command scripts for auto-reboot and daemon startup |
rc.local, rc(8) | command scripts for auto-reboot and daemon startup |
rc.network, rc(8) | command scripts for auto-reboot and daemon startup |
rc.pccard, rc(8) | command scripts for auto-reboot and daemon startup |
rc.resume, rc(8) | command scripts for auto-reboot and daemon startup |
rc.serial, rc(8) | command scripts for auto-reboot and daemon startup |
rc.shutdown, rc(8) | command scripts for auto-reboot and daemon startup |
RC(8) | MidnightBSD System Manager's Manual | RC(8) |
rc
— command
scripts for auto-reboot and daemon startup
rc |
rc.conf |
rc.conf.local |
rc.d/ |
rc.firewall |
rc.local |
rc.resume |
rc.shutdown |
rc.subr |
The rc
utility is the command script which
controls the automatic boot process after being called by
init(8). The
rc.local
script contains commands which are
pertinent only to a specific site. Typically, the
/usr/local/etc/rc.d/ mechanism is used instead of
rc.local
these days but if you want to use
rc.local
, it is still supported. In this case, it
should source /etc/rc.conf and contain additional
custom startup code for your system. The best way to handle
rc.local
, however, is to separate it 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.
The service(8) command provides a convenient interface to manage rc.d services.
The sysrc(8) command provides a scripting interface to modify system config files.
rc
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.nojail
” (no jails allowed) or
“nojailvnet
” (only allow
vnet-enabled jails) to the list of KEYWORDS to skip in
rcorder(8).firstboot
” to the list of
KEYWORDS to skip in
rcorder(8).nostart
” KEYWORD (refer to
rcorder(8)'s
-s
flag).run_rc_script
()
(from rc.subr(8)),
which sets $1 to
“start
”, and sources the script in a
subshell. Stop processing when the script that is the value of the
$early_late_divider has been run.rc.shutdown
rc.shutdown
or to
“unspecified
” if no argument was
passed.shutdown
” KEYWORD (refer to
rcorder(8)'s
-k
flag), reverse that order, and assign the
result to a variable.run_rc_script
()
(from rc.subr(8)),
which sets $1 to
“faststop
”, and sources the script
in a subshell.rc.d/
rc.d/
is located in
/etc/rc.d/. The following file naming conventions
are currently used in rc.d/
:
stop_boot
()
function (from
rc.subr(8)).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
forcestart
is given, ignore the
rc.conf(5) check and
start anyway.stop
forcestop
is given, ignore the
rc.conf(5) check and
attempt to stop.restart
stop
then a
start
.status
enable
disable
delete
service_delete_empty
’
is set to “YES
”,
/etc/rc.conf.d/$servicename will be deleted if
empty after modification.describe
extracommands
poll
enabled
rcvar
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 configuration files are normally read only once at the start
of a boot sequence; if a script needs to enable
or
disable
any other script that would run later in the
sequence, it must send a SIGALRM
to the rc process
(identified by $RC_PID
) to have it re-read the
files.
The following key points apply to old-style scripts in /usr/local/etc/rc.d/:
start
” as its first and only
argument. At shutdown time, it is passed the string
“stop
” as its first and 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.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
and -F
to
“preen” all the disks of minor inconsistencies resulting from
the last system shutdown. If this fails, then checks/repairs of serious
inconsistencies caused by hardware or software failure will be performed in
the background at the end of the booting process. 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/local script can execute
scripts from multiple rc.d/
directories. The default
location includes /usr/local/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 rc.firewall
script is used to
configure rules for the kernel based firewall service. It has several
possible options:
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 /etc/rc.d/apm for example, specifically check that they are on that architecture before starting the daemon.
Following tradition, all startup files reside in /etc.
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 . /etc/rc.subr name="foo" rcvar=foo_enable 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=foo_enable 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"
As all processes are killed by init(8) at shutdown, the explicit kill(1) is unnecessary, but is often included.
kill(1), rc.conf(5), init(8), rc.resume(8), rc.subr(8), rcorder(8), reboot(8), savecore(8), service(8), sysrc(8)
Practical rc.d scripting in BSD, https://docs.freebsd.org/en/articles/rc-scripting/.
The rc
utility appeared in
4.0BSD.
June 1, 2023 | midnightbsd-3.1 |