1 .\" Copyright (c) 1980, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Portions of this manual page are Copyrighted by
5 .\" The NetBSD Foundation.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
15 .\" 3. All advertising materials mentioning features or use of this software
16 .\" must display the following acknowledgement:
17 .\" This product includes software developed by the University of
18 .\" California, Berkeley and its contributors.
19 .\" 4. Neither the name of the University nor the names of its contributors
20 .\" may be used to endorse or promote products derived from this software
21 .\" without specific prior written permission.
23 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 .\" @(#)rc.8 8.2 (Berkeley) 12/11/93
38 .Dd September 23, 2013
43 .Nd command scripts for auto-reboot and daemon startup
56 utility is the command script which controls the automatic boot process
61 script contains commands which are pertinent only
64 .Pa /usr/local/etc/rc.d/
65 mechanism is used instead of
70 it is still supported.
71 In this case, it should source
73 and contain additional custom startup code for your system.
74 The best way to handle
76 however, is to separate it out into
78 style scripts and place them under
79 .Pa /usr/local/etc/rc.d/ .
82 file contains the global system configuration information referenced
83 by the startup scripts, while
85 contains the local system configuration.
92 directories contain scripts which will be automatically
93 executed at boot time and shutdown time.
98 .Va autoboot Ns = Ns Li yes
100 .Pq Va rc_fast Ns = Ns Li yes ,
103 scripts from performing the check for already running processes
104 (thus speeding up the boot process).
106 .Va rc_fast Ns = Ns Li yes
107 speedup will not occur when
109 is started up after exiting the single-user shell.
111 Determine whether the system is booting diskless,
113 .Pa /etc/rc.initdiskless
120 shell functions to use.
122 Load the configuration files.
124 Determine if booting in a jail,
127 (no jails allowed) or
129 (only allow vnet-enabled jails) to the list of KEYWORDS to skip in
134 to order the files in
143 Call each script in turn using
151 and sources the script in a subshell.
154 suffix then it is sourced directly into the current shell.
155 Stop processing when the script that is the value of the
156 .Va $early_late_divider
161 this time including the scripts in the
164 Ignore everything up to the
165 .Va $early_late_divider ,
166 then start executing the scripts as described above.
168 .Ss Operation of Nm rc.shutdown
175 shell functions to use.
177 Load the configuration files.
181 to order the files in
192 reverse that order, and assign the result to a variable.
194 Call each script in turn using
202 and sources the script in a subshell.
205 suffix then it is sourced directly into the current shell.
207 .Ss Contents of Nm rc.d/
211 The following file naming conventions are currently used in
213 .Bl -tag -width ".Pa ALLUPPERCASE" -offset indent
217 to ensure that certain operations are performed before others.
218 In order of startup, these are:
219 .Bl -tag -width ".Pa NETWORKING"
221 Ensure basic network services are running, including general
222 network configuration.
224 Ensure basic services
225 exist for services that start early (such as
227 because they are required by
231 Check-point before all general purpose daemons such as
236 Check-point before user login services
240 as well as services which might run commands as users
246 Scripts that are to be sourced into the current shell rather than a subshell
250 Extreme care must be taken in using this, as the startup sequence will
251 terminate if the script does.
253 Scripts that are sourced in a subshell.
254 The boot does not stop if such a script terminates with a non-zero status,
255 but a script can stop the boot if necessary by invoking the
261 Each script should contain
263 keywords, especially an appropriate
265 entry, and if necessary
271 Each script is expected to support at least the following arguments, which
272 are automatically supported if it uses the
275 .Bl -tag -width ".Cm restart" -offset indent
278 This should check that the service is to be started as specified by
280 Also checks if the service is already running and refuses to start if
282 This latter check is not performed by standard
284 scripts if the system is starting directly to multi-user mode, to
285 speed up the boot process.
290 check and start anyway.
292 If the service is to be started as specified by
295 This should check that the service is running and complain if it is not.
300 check and attempt to stop.
307 If the script starts a process (rather than performing a one-off
308 operation), show the status of the process.
309 Otherwise it is not necessary to support this argument.
310 Defaults to displaying the process ID of the program (if running).
312 If the script starts a process (rather than performing a one-off
313 operation), wait for the command to exit.
314 Otherwise it is not necessary to support this argument.
316 Return 0 if the service is enabled and 1 if it is not.
317 This command does not print anything.
321 variables are used to control the startup of the service (if any).
324 If a script must implement additional commands it can list them in
327 variable, and define their actions in a variable constructed from
328 the command name (see the
332 The following key points apply to old-style scripts in
333 .Pa /usr/local/etc/rc.d/ :
336 Scripts are only executed if their
338 matches the shell globbing pattern
340 and they are executable.
341 Any other files or directories present within the directory are silently
344 When a script is executed at boot time, it is passed the string
346 as its first and only argument.
347 At shutdown time, it is passed the string
349 as its first and only argument.
352 scripts are expected to handle these arguments appropriately.
353 If no action needs to be taken at a given time
354 (either boot time or shutdown time),
355 the script should exit successfully and without producing an error message.
357 The scripts within each directory are executed in lexicographical order.
358 If a specific order is required,
359 numbers may be used as a prefix to the existing filenames,
362 would be executed before
364 without the numeric prefixes the opposite would be true.
366 The output from each script is traditionally a space character,
367 followed by the name of the software package being started or shut down,
369 a trailing newline character (see the
373 .Sh SCRIPTS OF INTEREST
374 When an automatic reboot is in progress,
376 is invoked with the argument
378 One of the scripts run from
390 all the disks of minor inconsistencies resulting
391 from the last system shutdown.
392 If this fails, then checks/repairs of serious inconsistencies
393 caused by hardware or software failure will be performed
394 in the background at the end of the booting process.
397 is not set, when going from single-user to multi-user mode for example,
398 the script does not do anything.
402 script can execute scripts from multiple
405 The default location includes
406 .Pa /usr/local/etc/rc.d/ ,
407 but these may be overridden with the
414 script is used to set any special configurations for serial devices.
418 script is used to configure rules for the kernel based firewall
420 It has several possible options:
422 .Bl -tag -width ".Ar filename" -compact -offset indent
426 will try to protect just this machine
428 will try to protect a whole network
430 totally disables IP services except via
434 disables the loading of firewall rules
436 will load the rules in the given filename (full path required).
441 scripts are used to configure ATM network interfaces.
442 The interfaces are configured in three passes.
443 The first pass performs the initial interface configuration.
444 The second pass completes the interface configuration and defines PVCs and
445 permanent ATMARP entries.
446 The third pass starts any ATM daemons.
448 Most daemons, including network related daemons, have their own script in
450 which can be used to start, stop, and check the status of the service.
452 Any architecture specific scripts, such as
454 for example, specifically check that they are on that architecture
455 before starting the daemon.
457 Following tradition, all startup files reside in
460 .Bl -tag -compact -width Pa
463 .It Pa /etc/rc.conf.local
465 .It Pa /etc/rc.firewall
467 .It Pa /etc/rc.shutdown
469 .It Pa /var/run/dmesg.boot
471 results soon after the
476 buffer in the kernel no longer has this information.
479 The following is a minimal
482 Most scripts require little more than the following.
483 .Bd -literal -offset indent
488 # REQUIRE: bar_service_required_to_precede_foo
494 command="/usr/local/bin/foo"
500 Certain scripts may want to provide enhanced functionality.
501 The user may access this functionality through additional commands.
502 The script may list and define as many commands at it needs.
503 .Bd -literal -offset indent
508 # REQUIRE: bar_service_required_to_precede_foo
509 # BEFORE: baz_service_requiring_foo_to_precede_it
515 command="/usr/local/bin/foo"
516 extra_commands="nop hello"
517 hello_cmd="echo Hello World."
529 As all processes are killed by
531 at shutdown, the explicit
533 is unnecessary, but is often included.