Main index | Section 8 | 日本語 | Options |
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.
Operation of rc
Operation of rc.shutdown
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: | |
NETWORKING | |
Ensure basic network services are running, including general network configuration. | |
SERVERS | Ensure basic services exist for services that start early (such as nisdomain), because they are required by DAEMON below. |
DAEMON | Check-point before all general purpose daemons such as lpd and ntpd. |
LOGIN | Check-point before user login services ( inetd and sshd), as well as services which might run commands as users ( cron and sendmail). |
bar | Scripts that are sourced in a subshell. The boot does not stop if such a script terminates with a non-zero status, but a script can stop the boot if necessary by invoking the 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 | 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 FreeBSD scripts if the system is starting directly to multi-user mode, to speed up the boot process. 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. | |
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). |
enable | Enable the service in rc.conf(5). |
disable | |
Disable the service in rc.conf(5). | |
delete | Remove the service from rc.conf(5). If ‘service_delete_empty’ is set to "YES", /etc/rc.conf.d/$servicename will be deleted if empty after modification. |
describe | |
Print a short description of what the script does. | |
extracommands | |
Print the script's non-standard commands. | |
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. |
enabled | |
Return 0 if the service is enabled and 1 if it is not. This command does not print anything. | |
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/:
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:
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 /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.
/etc/rc
/etc/rc.conf /etc/rc.conf.local /etc/rc.d/ /etc/rc.firewall /etc/rc.local /etc/rc.shutdown /etc/rc.subr /var/run/dmesg.boot | |
dmesg(8) results soon after the rc process begins. Useful when dmesg(8) buffer in the kernel no longer has this information. | |
#!/bin/sh ## PROVIDE: foo # REQUIRE: bar_service_required_to_precede_foo
amp;. /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
amp;. /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.
https://docs.freebsd.org/en/articles/rc-scripting/
Practical rc.d scripting in BSD,
RC (8) | July 4, 2022 |
Main index | Section 8 | 日本語 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
“ | What is this horrible fascination with Unix? The operating system of the 1960s, still gaining in popularity in the 1990s. | ” |
— Donald A. Norman |