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
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.
159 Stop processing when the script that is the value of the
160 .Va $early_late_divider
163 Check again to see if the file
164 .Va ${firstboot_sentinel}
165 exists (in case it is located on a newly mounted file system)
166 and adjust the list of KEYWORDs to skip appropriately.
170 this time including the scripts in the
173 Ignore everything up to the
174 .Va $early_late_divider ,
175 then start executing the scripts as described above.
178 .Va ${firstboot_sentinel}
181 .Va ${firstboot_sentinel}-reboot
182 also exists (because it was created by a script), then delete it and reboot.
184 .Ss Operation of Nm rc.shutdown
191 shell functions to use.
193 Load the configuration files.
197 to order the files in
208 reverse that order, and assign the result to a variable.
210 Call each script in turn using
218 and sources the script in a subshell.
220 .Ss Contents of Nm rc.d/
224 The following file naming conventions are currently used in
226 .Bl -tag -width ".Pa ALLUPPERCASE" -offset indent
230 to ensure that certain operations are performed before others.
231 In order of startup, these are:
232 .Bl -tag -width ".Pa NETWORKING"
234 Ensure basic network services are running, including general
235 network configuration.
237 Ensure basic services
238 exist for services that start early (such as
240 because they are required by
244 Check-point before all general purpose daemons such as
249 Check-point before user login services
253 as well as services which might run commands as users
259 Scripts that are sourced in a subshell.
260 The boot does not stop if such a script terminates with a non-zero status,
261 but a script can stop the boot if necessary by invoking the
267 Each script should contain
269 keywords, especially an appropriate
271 entry, and if necessary
277 Each script is expected to support at least the following arguments, which
278 are automatically supported if it uses the
281 .Bl -tag -width ".Cm restart" -offset indent
284 This should check that the service is to be started as specified by
286 Also checks if the service is already running and refuses to start if
288 This latter check is not performed by standard
290 scripts if the system is starting directly to multi-user mode, to
291 speed up the boot process.
296 check and start anyway.
298 If the service is to be started as specified by
301 This should check that the service is running and complain if it is not.
306 check and attempt to stop.
313 If the script starts a process (rather than performing a one-off
314 operation), show the status of the process.
315 Otherwise it is not necessary to support this argument.
316 Defaults to displaying the process ID of the program (if running).
318 Enable the service in
321 Disable the service in
324 Remove the service from
327 .Ql Li service_delete_empty
330 .Pa /etc/rc.conf.d/$servicename
331 will be deleted if empty after modification.
333 Print a short description of what the script does.
335 Print the script's non-standard commands.
337 If the script starts a process (rather than performing a one-off
338 operation), wait for the command to exit.
339 Otherwise it is not necessary to support this argument.
341 Return 0 if the service is enabled and 1 if it is not.
342 This command does not print anything.
346 variables are used to control the startup of the service (if any).
349 If a script must implement additional commands it can list them in
352 variable, and define their actions in a variable constructed from
353 the command name (see the
357 The following key points apply to old-style scripts in
358 .Pa /usr/local/etc/rc.d/ :
361 Scripts are only executed if their
363 matches the shell globbing pattern
365 and they are executable.
366 Any other files or directories present within the directory are silently
369 When a script is executed at boot time, it is passed the string
371 as its first and only argument.
372 At shutdown time, it is passed the string
374 as its first and only argument.
377 scripts are expected to handle these arguments appropriately.
378 If no action needs to be taken at a given time
379 (either boot time or shutdown time),
380 the script should exit successfully and without producing an error message.
382 The scripts within each directory are executed in lexicographical order.
383 If a specific order is required,
384 numbers may be used as a prefix to the existing filenames,
387 would be executed before
389 without the numeric prefixes the opposite would be true.
391 The output from each script is traditionally a space character,
392 followed by the name of the software package being started or shut down,
394 a trailing newline character (see the
398 .Sh SCRIPTS OF INTEREST
399 When an automatic reboot is in progress,
401 is invoked with the argument
403 One of the scripts run from
415 all the disks of minor inconsistencies resulting
416 from the last system shutdown.
417 If this fails, then checks/repairs of serious inconsistencies
418 caused by hardware or software failure will be performed
419 in the background at the end of the booting process.
422 is not set, when going from single-user to multi-user mode for example,
423 the script does not do anything.
427 script can execute scripts from multiple
430 The default location includes
431 .Pa /usr/local/etc/rc.d/ ,
432 but these may be overridden with the
439 script is used to set any special configurations for serial devices.
443 script is used to configure rules for the kernel based firewall
445 It has several possible options:
447 .Bl -tag -width ".Ar filename" -compact -offset indent
451 will try to protect just this machine
453 will try to protect a whole network
455 totally disables IP services except via
459 disables the loading of firewall rules
461 will load the rules in the given filename (full path required).
464 Most daemons, including network related daemons, have their own script in
466 which can be used to start, stop, and check the status of the service.
468 Any architecture specific scripts, such as
470 for example, specifically check that they are on that architecture
471 before starting the daemon.
473 Following tradition, all startup files reside in
476 .Bl -tag -compact -width Pa
479 .It Pa /etc/rc.conf.local
481 .It Pa /etc/rc.firewall
483 .It Pa /etc/rc.shutdown
485 .It Pa /var/run/dmesg.boot
487 results soon after the
492 buffer in the kernel no longer has this information.
495 The following is a minimal
498 Most scripts require little more than the following.
499 .Bd -literal -offset indent
504 # REQUIRE: bar_service_required_to_precede_foo
510 command="/usr/local/bin/foo"
516 Certain scripts may want to provide enhanced functionality.
517 The user may access this functionality through additional commands.
518 The script may list and define as many commands at it needs.
519 .Bd -literal -offset indent
524 # REQUIRE: bar_service_required_to_precede_foo
525 # BEFORE: baz_service_requiring_foo_to_precede_it
531 command="/usr/local/bin/foo"
532 extra_commands="nop hello"
533 hello_cmd="echo Hello World."
545 As all processes are killed by
547 at shutdown, the explicit
549 is unnecessary, but is often included.