| NETWORKING | Ensure basic network services are running, including general network configuration (network1, network2, network3). |
| SERVERS | Ensure basic services (such as NETWORKING, ppp-user, syslogd, and isdnd) 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 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). |
|
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 .Fx 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). |
| 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). |
|
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 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 rc.early script is run very early in the startup process, immediately before the file system check. The rc.early script is deprecated. Any commands in this file should be separated out into rc.d/ style scripts and integrated into the rc system.
The /etc/rc.d/local script can execute scripts from multiple rc.d/ directories. The default locations are /usr/local/etc/rc.d/ and /usr/X11R6/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/network* scripts are used to start the network. The network is started in several passes. The first pass, /etc/rc.d/network1, sets the hostname and domainname and configures the network interfaces. The /etc/rc.d/network2 script starts routing and sets routing options. The /etc/rc.d/network3 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 kernel based firewall service. It has several possible options:
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), rc.conf(5), init(8), rcorder(8), rc.subr(8), reboot(8), savecore(8)
HISTORY