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
52 utility is the command script which controls the automatic boot process
57 script contains commands which are pertinent only
60 .Pa /usr/local/etc/rc.d/
61 mechanism is used instead of
66 it is still supported.
67 In this case, it should source
69 and contain additional custom startup code for your system.
70 The best way to handle
72 however, is to separate it out into
74 style scripts and place them under
75 .Pa /usr/local/etc/rc.d/ .
78 file contains the global system configuration information referenced
79 by the startup scripts, while
81 contains the local system configuration.
88 directories contain scripts which will be automatically
89 executed at boot time and shutdown time.
91 The sysrc(8) command provides a scripting interface to modify system
97 .Va autoboot Ns = Ns Li yes
99 .Pq Va rc_fast Ns = Ns Li yes ,
102 scripts from performing the check for already running processes
103 (thus speeding up the boot process).
105 .Va rc_fast Ns = Ns Li yes
106 speedup will not occur when
108 is started up after exiting the single-user shell.
110 Determine whether the system is booting diskless,
112 .Pa /etc/rc.initdiskless
119 shell functions to use.
121 Load the configuration files.
123 Determine if booting in a jail,
126 (no jails allowed) or
128 (only allow vnet-enabled jails) to the list of KEYWORDS to skip in
132 .Va ${firstboot_sentinel}
135 to the list of KEYWORDS to skip in
140 to order the files in
149 Call each script in turn using
157 and sources the script in a subshell.
160 suffix then it is sourced directly into the current shell.
161 Stop processing when the script that is the value of the
162 .Va $early_late_divider
165 Check again to see if the file
166 .Va ${firstboot_sentinel}
167 exists (in case it is located on a newly mounted file system)
168 and adjust the list of KEYWORDs to skip appropriately.
172 this time including the scripts in the
175 Ignore everything up to the
176 .Va $early_late_divider ,
177 then start executing the scripts as described above.
180 .Va ${firstboot_sentinel}
183 .Va ${firstboot_sentinel}-reboot
184 also exists (because it was created by a script), then delete it and reboot.
186 .Ss Operation of Nm rc.shutdown
193 shell functions to use.
195 Load the configuration files.
199 to order the files in
210 reverse that order, and assign the result to a variable.
212 Call each script in turn using
220 and sources the script in a subshell.
223 suffix then it is sourced directly into the current shell.
225 .Ss Contents of Nm rc.d/
229 The following file naming conventions are currently used in
231 .Bl -tag -width ".Pa ALLUPPERCASE" -offset indent
235 to ensure that certain operations are performed before others.
236 In order of startup, these are:
237 .Bl -tag -width ".Pa NETWORKING"
239 Ensure basic network services are running, including general
240 network configuration.
242 Ensure basic services
243 exist for services that start early (such as
245 because they are required by
249 Check-point before all general purpose daemons such as
254 Check-point before user login services
258 as well as services which might run commands as users
264 Scripts that are to be sourced into the current shell rather than a subshell
268 Extreme care must be taken in using this, as the startup sequence will
269 terminate if the script does.
271 Scripts that are sourced in a subshell.
272 The boot does not stop if such a script terminates with a non-zero status,
273 but a script can stop the boot if necessary by invoking the
279 Each script should contain
281 keywords, especially an appropriate
283 entry, and if necessary
289 Each script is expected to support at least the following arguments, which
290 are automatically supported if it uses the
293 .Bl -tag -width ".Cm restart" -offset indent
296 This should check that the service is to be started as specified by
298 Also checks if the service is already running and refuses to start if
300 This latter check is not performed by standard
302 scripts if the system is starting directly to multi-user mode, to
303 speed up the boot process.
308 check and start anyway.
310 If the service is to be started as specified by
313 This should check that the service is running and complain if it is not.
318 check and attempt to stop.
325 If the script starts a process (rather than performing a one-off
326 operation), show the status of the process.
327 Otherwise it is not necessary to support this argument.
328 Defaults to displaying the process ID of the program (if running).
330 Print a short description of what the script does.
332 Print the script's non-standard commands.
334 If the script starts a process (rather than performing a one-off
335 operation), wait for the command to exit.
336 Otherwise it is not necessary to support this argument.
338 Return 0 if the service is enabled and 1 if it is not.
339 This command does not print anything.
343 variables are used to control the startup of the service (if any).
346 If a script must implement additional commands it can list them in
349 variable, and define their actions in a variable constructed from
350 the command name (see the
354 The following key points apply to old-style scripts in
355 .Pa /usr/local/etc/rc.d/ :
358 Scripts are only executed if their
360 matches the shell globbing pattern
362 and they are executable.
363 Any other files or directories present within the directory are silently
366 When a script is executed at boot time, it is passed the string
368 as its first and only argument.
369 At shutdown time, it is passed the string
371 as its first and only argument.
374 scripts are expected to handle these arguments appropriately.
375 If no action needs to be taken at a given time
376 (either boot time or shutdown time),
377 the script should exit successfully and without producing an error message.
379 The scripts within each directory are executed in lexicographical order.
380 If a specific order is required,
381 numbers may be used as a prefix to the existing filenames,
384 would be executed before
386 without the numeric prefixes the opposite would be true.
388 The output from each script is traditionally a space character,
389 followed by the name of the software package being started or shut down,
391 a trailing newline character (see the
395 .Sh SCRIPTS OF INTEREST
396 When an automatic reboot is in progress,
398 is invoked with the argument
400 One of the scripts run from
412 all the disks of minor inconsistencies resulting
413 from the last system shutdown.
414 If this fails, then checks/repairs of serious inconsistencies
415 caused by hardware or software failure will be performed
416 in the background at the end of the booting process.
419 is not set, when going from single-user to multi-user mode for example,
420 the script does not do anything.
424 script can execute scripts from multiple
427 The default location includes
428 .Pa /usr/local/etc/rc.d/ ,
429 but these may be overridden with the
436 script is used to set any special configurations for serial devices.
440 script is used to configure rules for the kernel based firewall
442 It has several possible options:
444 .Bl -tag -width ".Ar filename" -compact -offset indent
448 will try to protect just this machine
450 will try to protect a whole network
452 totally disables IP services except via
456 disables the loading of firewall rules
458 will load the rules in the given filename (full path required).
461 Most daemons, including network related daemons, have their own script in
463 which can be used to start, stop, and check the status of the service.
465 Any architecture specific scripts, such as
467 for example, specifically check that they are on that architecture
468 before starting the daemon.
470 Following tradition, all startup files reside in
473 .Bl -tag -compact -width Pa
476 .It Pa /etc/rc.conf.local
478 .It Pa /etc/rc.firewall
480 .It Pa /etc/rc.shutdown
482 .It Pa /var/run/dmesg.boot
484 results soon after the
489 buffer in the kernel no longer has this information.
492 The following is a minimal
495 Most scripts require little more than the following.
496 .Bd -literal -offset indent
501 # REQUIRE: bar_service_required_to_precede_foo
507 command="/usr/local/bin/foo"
513 Certain scripts may want to provide enhanced functionality.
514 The user may access this functionality through additional commands.
515 The script may list and define as many commands at it needs.
516 .Bd -literal -offset indent
521 # REQUIRE: bar_service_required_to_precede_foo
522 # BEFORE: baz_service_requiring_foo_to_precede_it
528 command="/usr/local/bin/foo"
529 extra_commands="nop hello"
530 hello_cmd="echo Hello World."
542 As all processes are killed by
544 at shutdown, the explicit
546 is unnecessary, but is often included.