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
32 .\" $FreeBSD: src/share/man/man8/rc.8,v 1.22 2002/12/12 17:25:58 ru Exp $
39 .Nd command scripts for auto-reboot and daemon startup
53 utility is the command script which controls the automatic boot process
60 scripts contains commands which are pertinent only to a specific site.
62 .Pa /usr/local/etc/rc.d/
67 these days but if you want to use them it is still supported.
68 In this case, they should source
70 and contain additional custom startup and shutdown code for your system.
71 The best way to handle
74 .Nm rc.shutdown.local ,
75 however, is to separate them out into
77 style scripts and place them under
78 .Pa /usr/local/etc/rc.d/ .
81 file contains the global system configuration information referenced
82 by the startup scripts, while
84 contains the local system configuration.
91 directories contain scripts which will be automatically
92 executed at boot time and shutdown time.
100 shell functions to use.
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.
120 to the list of KEYWORDS to skip in
125 to order the files in
133 and assign the result to a variable.
135 Call each script in turn using
143 and sources the script in a subshell.
146 suffix then it is sourced directly into the current shell.
152 .Ss Operation of Nm rc.shutdown
159 shell functions to use.
163 to order the files in
171 reverse that order, and assign the result to a variable.
173 Call each script in turn using
181 and sources the script in a subshell.
184 suffix then it is sourced directly into the current shell.
186 .Ss Contents of Nm rc.d/
190 The following file naming conventions are currently used in
192 .Bl -tag -width ".Pa ALLUPPERCASE" -offset indent
196 to ensure that certain operations are performed before others.
197 In order of startup, these are:
198 .Bl -tag -width ".Pa NETWORKING"
200 Ensure basic network services are running, including general
201 network configuration
202 .Pq Pa netif , routing , network_ipv6 , ppp .
204 Ensure basic services (such as
208 exist for services that start early (such as
210 because they are required by
214 Check-point before all general purpose daemons such as
219 Check-point before user login services
223 as well as services which might run commands as users
229 Scripts that are to be sourced into the current shell rather than a subshell
233 Extreme care must be taken in using this, as the startup sequence will
234 terminate if the script terminates.
236 Scripts that are sourced in a subshell.
237 These can stop the boot if necessary with the following shell
239 .Bd -literal -offset indent
240 if [ "$autoboot" = yes ]; then
246 Note that this should be used extremely sparingly!
249 Each script should contain
251 keywords, especially an appropriate
253 entry, and if necessary
259 Each script is expected to support at least the following arguments, which
260 are automatically supported if it uses the
263 .Bl -tag -width ".Cm restart" -offset indent
266 This should check that the service is to be started as specified by
268 Also checks if the service is already running and refuses to start if
270 This latter check is not performed by standard
272 scripts if the system is starting directly to multi-user mode, to
273 speed up the boot process.
276 is given, skip the PID check.
281 check and start anyway.
283 If the service is to be started as specified by
286 This should check that the service is running and complain if it is not.
291 check and attempt to stop.
302 to the program(s) associated with the service.
303 Note that not all scripts enable the
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.
318 variables are used to control the startup of the service (if any).
321 If a script must implement additional commands it can list them in
324 variable, and define their actions in a variable constructed from
325 the command name (see the
329 The following key points apply to old-style scripts in
330 .Pa /usr/local/etc/rc.d/ :
333 Scripts are only executed if their
335 matches the shell globbing pattern
337 and they are executable.
338 Any other files or directories present within the directory are silently
341 When a script is executed at boot time, it is passed the string
343 as its only argument.
344 At shutdown time, it is passed the string
346 as its only argument.
349 scripts are expected to handle these arguments appropriately.
350 If no action needs to be taken at a given time
351 (either boot time or shutdown time),
352 the script should exit successfully and without producing an error message.
354 The scripts within each directory are executed in lexicographical order.
355 If a specific order is required,
356 numbers may be used as a prefix to the existing filenames,
359 would be executed before
361 without the numeric prefixes the opposite would be true.
363 The output from each script is traditionally a space character,
364 followed by the name of the software package being started or shut down,
366 a trailing newline character (see the
370 .Sh SCRIPTS OF INTEREST
371 When an automatic reboot is in progress,
373 is invoked with the argument
375 One of the scripts run from
387 file systems of minor inconsistencies resulting
388 from the last system shutdown.
389 If preening fails further action depends on the
407 is not set, when going from single-user to multi-user mode for example,
408 the script does not do anything.
411 .Pa /etc/rc.d/localdaemons
412 script can execute scripts from multiple
415 The default locations are
416 .Pa /usr/local/etc/rc.d/
418 .Pa /usr/pkg/etc/rc.d/ ,
419 but these may be overridden with the
426 script is used to set any special configurations for serial devices.
429 .Pa /etc/rc.d/{net*,routing}
430 scripts are used to start the network.
431 The network is started in several passes.
433 .Pa /etc/rc.d/netif ,
434 configures the network
437 .Pa /etc/rc.d/routing
438 script starts routing and sets routing options.
440 .Pa /etc/rc.d/netoptions
441 script sets additional networking options.
443 .Pa /etc/rc.d/network_ipv6
444 script configures IPv6 interfaces and options.
448 script is used to configure rules for the
450 kernel based firewall
452 It has several possible options:
454 .Bl -tag -width ".Ar filename" -compact -offset indent
458 will try to protect just this machine
460 will try to protect a whole network
462 totally disables IP services except via
466 disables the loading of firewall rules
468 will load the rules in the given filename (full path required).
471 Most daemons, including network related daemons, have their own script in
473 which can be used to start, stop, and check the status of the service.
475 Any architecture specific scripts, such as
476 specifically check that they are on that architecture
477 before starting the daemon.
479 Following tradition, all startup files reside in
482 .Bl -tag -compact -width ".Pa /etc/rc.shutdown.local"
485 .It Pa /etc/rc.conf.local
487 .It Pa /etc/rc.firewall
489 .It Pa /etc/rc.shutdown
490 .It Pa /etc/rc.shutdown.local
494 The following is a minimal
497 Most scripts require little more than the following.
498 .Bd -literal -offset indent
503 # REQUIRE: bar_service_required_to_precede_foo
504 # BEFORE: baz_service_requiring_foo_to_precede_it
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 The following is a simple, hypothetical example of an old-style
546 .Pa /usr/local/etc/rc.d/
548 which would start a daemon at boot time,
549 and kill it at shutdown time.
550 .Bd -literal -offset indent
553 # initialization/shutdown script for foobar package
557 /usr/local/sbin/foo -d && echo -n ' foo'
560 kill `cat /var/run/foo.pid` && echo -n ' foo'
563 echo "unknown option: $1 - should be 'start' or 'stop'" >&2
568 As all processes are killed by
570 at shutdown, the explicit
572 is unnecessary, but is often included.
590 facility was implemented in