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.
94 command provides a convenient interface to manage rc.d services.
98 command provides a scripting interface to modify system config files.
103 .Va autoboot Ns = Ns Li yes
105 .Pq Va rc_fast Ns = Ns Li yes ,
108 scripts from performing the check for already running processes
109 (thus speeding up the boot process).
111 .Va rc_fast Ns = Ns Li yes
112 speedup will not occur when
114 is started up after exiting the single-user shell.
116 Determine whether the system is booting diskless,
118 .Pa /etc/rc.initdiskless
125 shell functions to use.
127 Load the configuration files.
129 Determine if booting in a jail,
132 (no jails allowed) or
134 (only allow vnet-enabled jails) to the list of KEYWORDS to skip in
138 .Va ${firstboot_sentinel}
141 to the list of KEYWORDS to skip in
146 to order the files in
155 Call each script in turn using
163 and sources the script in a subshell.
164 Stop processing when the script that is the value of the
165 .Va $early_late_divider
168 Check again to see if the file
169 .Va ${firstboot_sentinel}
170 exists (in case it is located on a newly mounted file system)
171 and adjust the list of KEYWORDs to skip appropriately.
175 this time including the scripts in the
178 Ignore everything up to the
179 .Va $early_late_divider ,
180 then start executing the scripts as described above.
183 .Va ${firstboot_sentinel}
186 .Va ${firstboot_sentinel}-reboot
187 also exists (because it was created by a script), then delete it and reboot.
189 .Ss Operation of Nm rc.shutdown
194 to the value of the first argument passed to
198 if no argument was passed.
204 shell functions to use.
206 Load the configuration files.
210 to order the files in
221 reverse that order, and assign the result to a variable.
223 Call each script in turn using
231 and sources the script in a subshell.
233 .Ss Contents of Nm rc.d/
237 The following file naming conventions are currently used in
239 .Bl -tag -width ".Pa ALLUPPERCASE" -offset indent
243 to ensure that certain operations are performed before others.
244 In order of startup, these are:
245 .Bl -tag -width ".Pa FILESYSTEMS"
247 Ensure that root and other critical file systems are mounted.
249 .Va $early_late_divider .
251 Ensure basic network services are running, including general
252 network configuration.
254 Ensure basic services
255 exist for services that start early (such as
257 because they are required by
261 Check-point before all general purpose daemons such as
266 Check-point before user login services
270 as well as services which might run commands as users
276 Scripts that are sourced in a subshell.
277 The boot does not stop if such a script terminates with a non-zero status,
278 but a script can stop the boot if necessary by invoking the
284 Each script should contain
286 keywords, especially an appropriate
288 entry, and if necessary
294 Each script is expected to support at least the following arguments, which
295 are automatically supported if it uses the
298 .Bl -tag -width ".Cm restart" -offset indent
301 This should check that the service is to be started as specified by
303 Also checks if the service is already running and refuses to start if
305 This latter check is not performed by standard
307 scripts if the system is starting directly to multi-user mode, to
308 speed up the boot process.
313 check and start anyway.
315 If the service is to be started as specified by
318 This should check that the service is running and complain if it is not.
323 check and attempt to stop.
330 If the script starts a process (rather than performing a one-off
331 operation), show the status of the process.
332 Otherwise it is not necessary to support this argument.
333 Defaults to displaying the process ID of the program (if running).
335 Enable the service in
338 Disable the service in
341 Remove the service from
344 .Ql Li service_delete_empty
347 .Pa /etc/rc.conf.d/$servicename
348 will be deleted if empty after modification.
350 Print a short description of what the script does.
352 Print the script's non-standard commands.
354 If the script starts a process (rather than performing a one-off
355 operation), wait for the command to exit.
356 Otherwise it is not necessary to support this argument.
358 Return 0 if the service is enabled and 1 if it is not.
359 This command does not print anything.
363 variables are used to control the startup of the service (if any).
366 If a script must implement additional commands it can list them in
369 variable, and define their actions in a variable constructed from
370 the command name (see the
374 The following key points apply to old-style scripts in
375 .Pa /usr/local/etc/rc.d/ :
378 Scripts are only executed if their
380 matches the shell globbing pattern
382 and they are executable.
383 Any other files or directories present within the directory are silently
386 When a script is executed at boot time, it is passed the string
388 as its first and only argument.
389 At shutdown time, it is passed the string
391 as its first and only argument.
394 scripts are expected to handle these arguments appropriately.
395 If no action needs to be taken at a given time
396 (either boot time or shutdown time),
397 the script should exit successfully and without producing an error message.
399 The scripts within each directory are executed in lexicographical order.
400 If a specific order is required,
401 numbers may be used as a prefix to the existing filenames,
404 would be executed before
406 without the numeric prefixes the opposite would be true.
408 The output from each script is traditionally a space character,
409 followed by the name of the software package being started or shut down,
411 a trailing newline character.
413 .Sh SCRIPTS OF INTEREST
414 When an automatic reboot is in progress,
416 is invoked with the argument
418 One of the scripts run from
430 all the disks of minor inconsistencies resulting
431 from the last system shutdown.
432 If this fails, then checks/repairs of serious inconsistencies
433 caused by hardware or software failure will be performed
434 in the background at the end of the booting process.
437 is not set, when going from single-user to multi-user mode for example,
438 the script does not do anything.
442 script can execute scripts from multiple
445 The default location includes
446 .Pa /usr/local/etc/rc.d/ ,
447 but these may be overridden with the
454 script is used to set any special configurations for serial devices.
458 script is used to configure rules for the kernel based firewall
460 It has several possible options:
462 .Bl -tag -width ".Ar filename" -compact -offset indent
466 will try to protect just this machine
468 will try to protect a whole network
470 totally disables IP services except via
474 disables the loading of firewall rules
476 will load the rules in the given filename (full path required).
479 Most daemons, including network related daemons, have their own script in
481 which can be used to start, stop, and check the status of the service.
483 Any architecture specific scripts, such as
485 for example, specifically check that they are on that architecture
486 before starting the daemon.
488 Following tradition, all startup files reside in
491 .Bl -tag -compact -width Pa
494 .It Pa /etc/rc.conf.local
496 .It Pa /etc/rc.firewall
498 .It Pa /etc/rc.shutdown
500 .It Pa /var/run/dmesg.boot
502 results soon after the
507 buffer in the kernel no longer has this information.
510 The following is a minimal
513 Most scripts require little more than the following.
514 .Bd -literal -offset indent
519 # REQUIRE: bar_service_required_to_precede_foo
525 command="/usr/local/bin/foo"
531 Certain scripts may want to provide enhanced functionality.
532 The user may access this functionality through additional commands.
533 The script may list and define as many commands at it needs.
534 .Bd -literal -offset indent
539 # REQUIRE: bar_service_required_to_precede_foo
540 # BEFORE: baz_service_requiring_foo_to_precede_it
546 command="/usr/local/bin/foo"
547 extra_commands="nop hello"
548 hello_cmd="echo Hello World."
560 As all processes are killed by
562 at shutdown, the explicit
564 is unnecessary, but is often included.