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. Neither the name of the University nor the names of its contributors
16 .\" may be used to endorse or promote products derived from this software
17 .\" without specific prior written permission.
19 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .\" @(#)rc.8 8.2 (Berkeley) 12/11/93
34 .Dd September 18, 2018
39 .Nd command scripts for auto-reboot and daemon startup
53 utility is the command script which controls the automatic boot process
58 script contains commands which are pertinent only
61 .Pa /usr/local/etc/rc.d/
62 mechanism is used instead of
67 it is still supported.
68 In this case, it should source
70 and contain additional custom startup code for your system.
71 The best way to handle
73 however, is to separate it out into
75 style scripts and place them under
76 .Pa /usr/local/etc/rc.d/ .
79 file contains the global system configuration information referenced
80 by the startup scripts, while
82 contains the local system configuration.
89 directories contain scripts which will be automatically
90 executed at boot time and shutdown time.
92 The sysrc(8) command provides a scripting interface to modify system
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
133 .Va ${firstboot_sentinel}
136 to the list of KEYWORDS to skip in
141 to order the files in
150 Call each script in turn using
158 and sources the script in a subshell.
161 suffix then it is sourced directly into the current shell.
162 Stop processing when the script that is the value of the
163 .Va $early_late_divider
166 Check again to see if the file
167 .Va ${firstboot_sentinel}
168 exists (in case it is located on a newly mounted file system)
169 and adjust the list of KEYWORDs to skip appropriately.
173 this time including the scripts in the
176 Ignore everything up to the
177 .Va $early_late_divider ,
178 then start executing the scripts as described above.
181 .Va ${firstboot_sentinel}
184 .Va ${firstboot_sentinel}-reboot
185 also exists (because it was created by a script), then delete it and reboot.
187 .Ss Operation of Nm rc.shutdown
194 shell functions to use.
196 Load the configuration files.
200 to order the files in
211 reverse that order, and assign the result to a variable.
213 Call each script in turn using
221 and sources the script in a subshell.
224 suffix then it is sourced directly into the current shell.
226 .Ss Contents of Nm rc.d/
230 The following file naming conventions are currently used in
232 .Bl -tag -width ".Pa ALLUPPERCASE" -offset indent
236 to ensure that certain operations are performed before others.
237 In order of startup, these are:
238 .Bl -tag -width ".Pa NETWORKING"
240 Ensure basic network services are running, including general
241 network configuration.
243 Ensure basic services
244 exist for services that start early (such as
246 because they are required by
250 Check-point before all general purpose daemons such as
255 Check-point before user login services
259 as well as services which might run commands as users
265 Scripts that are to be sourced into the current shell rather than a subshell
269 Extreme care must be taken in using this, as the startup sequence will
270 terminate if the script does.
272 Scripts that are sourced in a subshell.
273 The boot does not stop if such a script terminates with a non-zero status,
274 but a script can stop the boot if necessary by invoking the
280 Each script should contain
282 keywords, especially an appropriate
284 entry, and if necessary
290 Each script is expected to support at least the following arguments, which
291 are automatically supported if it uses the
294 .Bl -tag -width ".Cm restart" -offset indent
297 This should check that the service is to be started as specified by
299 Also checks if the service is already running and refuses to start if
301 This latter check is not performed by standard
303 scripts if the system is starting directly to multi-user mode, to
304 speed up the boot process.
309 check and start anyway.
311 If the service is to be started as specified by
314 This should check that the service is running and complain if it is not.
319 check and attempt to stop.
326 If the script starts a process (rather than performing a one-off
327 operation), show the status of the process.
328 Otherwise it is not necessary to support this argument.
329 Defaults to displaying the process ID of the program (if running).
331 Enable the service in
334 Disable the service in
337 Remove the service from
340 .Ql Li service_delete_empty
343 .Pa /etc/rc.conf.d/$servicename
344 will be deleted if empty after modification.
346 Print a short description of what the script does.
348 Print the script's non-standard commands.
350 If the script starts a process (rather than performing a one-off
351 operation), wait for the command to exit.
352 Otherwise it is not necessary to support this argument.
354 Return 0 if the service is enabled and 1 if it is not.
355 This command does not print anything.
359 variables are used to control the startup of the service (if any).
362 If a script must implement additional commands it can list them in
365 variable, and define their actions in a variable constructed from
366 the command name (see the
370 The following key points apply to old-style scripts in
371 .Pa /usr/local/etc/rc.d/ :
374 Scripts are only executed if their
376 matches the shell globbing pattern
378 and they are executable.
379 Any other files or directories present within the directory are silently
382 When a script is executed at boot time, it is passed the string
384 as its first and only argument.
385 At shutdown time, it is passed the string
387 as its first and only argument.
390 scripts are expected to handle these arguments appropriately.
391 If no action needs to be taken at a given time
392 (either boot time or shutdown time),
393 the script should exit successfully and without producing an error message.
395 The scripts within each directory are executed in lexicographical order.
396 If a specific order is required,
397 numbers may be used as a prefix to the existing filenames,
400 would be executed before
402 without the numeric prefixes the opposite would be true.
404 The output from each script is traditionally a space character,
405 followed by the name of the software package being started or shut down,
407 a trailing newline character (see the
411 .Sh SCRIPTS OF INTEREST
412 When an automatic reboot is in progress,
414 is invoked with the argument
416 One of the scripts run from
428 all the disks of minor inconsistencies resulting
429 from the last system shutdown.
430 If this fails, then checks/repairs of serious inconsistencies
431 caused by hardware or software failure will be performed
432 in the background at the end of the booting process.
435 is not set, when going from single-user to multi-user mode for example,
436 the script does not do anything.
440 script can execute scripts from multiple
443 The default location includes
444 .Pa /usr/local/etc/rc.d/ ,
445 but these may be overridden with the
452 script is used to set any special configurations for serial devices.
456 script is used to configure rules for the kernel based firewall
458 It has several possible options:
460 .Bl -tag -width ".Ar filename" -compact -offset indent
464 will try to protect just this machine
466 will try to protect a whole network
468 totally disables IP services except via
472 disables the loading of firewall rules
474 will load the rules in the given filename (full path required).
477 Most daemons, including network related daemons, have their own script in
479 which can be used to start, stop, and check the status of the service.
481 Any architecture specific scripts, such as
483 for example, specifically check that they are on that architecture
484 before starting the daemon.
486 Following tradition, all startup files reside in
489 .Bl -tag -compact -width Pa
492 .It Pa /etc/rc.conf.local
494 .It Pa /etc/rc.firewall
496 .It Pa /etc/rc.shutdown
498 .It Pa /var/run/dmesg.boot
500 results soon after the
505 buffer in the kernel no longer has this information.
508 The following is a minimal
511 Most scripts require little more than the following.
512 .Bd -literal -offset indent
517 # REQUIRE: bar_service_required_to_precede_foo
523 command="/usr/local/bin/foo"
529 Certain scripts may want to provide enhanced functionality.
530 The user may access this functionality through additional commands.
531 The script may list and define as many commands at it needs.
532 .Bd -literal -offset indent
537 # REQUIRE: bar_service_required_to_precede_foo
538 # BEFORE: baz_service_requiring_foo_to_precede_it
544 command="/usr/local/bin/foo"
545 extra_commands="nop hello"
546 hello_cmd="echo Hello World."
558 As all processes are killed by
560 at shutdown, the explicit
562 is unnecessary, but is often included.