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 $
33 .Dd September 28, 2009
38 .Nd command scripts for auto-reboot and daemon startup
52 utility is the command script which controls the automatic boot process
59 scripts contains commands which are pertinent only to a specific site.
61 .Pa /usr/local/etc/rc.d/
66 these days but if you want to use them it is still supported.
67 In this case, they should source
69 and contain additional custom startup and shutdown code for your system.
70 The best way to handle
73 .Nm rc.shutdown.local ,
74 however, is to separate them out into
76 style scripts and place them under
77 .Pa /usr/local/etc/rc.d/ .
80 file contains the global system configuration information referenced
81 by the startup scripts, while
83 contains the local system configuration.
90 directories contain scripts which will be automatically
91 executed at boot time and shutdown time.
99 shell functions to use.
102 .Va autoboot Ns = Ns Li yes
104 .Pq Va rc_fast Ns = Ns Li yes ,
107 scripts from performing the check for already running processes
108 (thus speeding up the boot process).
110 .Va rc_fast Ns = Ns Li yes
111 speedup will not occur when
113 is started up after exiting the single-user shell.
117 to order the files in
125 and assign the result to a variable.
127 Call each script in turn using
135 and sources the script in a subshell.
138 suffix then it is sourced directly into the current shell.
140 .Ss Operation of Nm rc.shutdown
147 shell functions to use.
151 to order the files in
159 reverse that order, and assign the result to a variable.
161 Call each script in turn using
169 and sources the script in a subshell.
172 suffix then it is sourced directly into the current shell.
174 .Ss Contents of Nm rc.d/
178 The following file naming conventions are currently used in
180 .Bl -tag -width ".Pa ALLUPPERCASE" -offset indent
184 to ensure that certain operations are performed before others.
185 In order of startup, these are:
186 .Bl -tag -width ".Pa NETWORKING"
188 Ensure basic network services are running, including general
189 network configuration
190 .Pq Pa netif , routing , network_ipv6 , ppp-user .
192 Ensure basic services (such as
196 exist for services that start early (such as
198 because they are required by
202 Check-point before all general purpose daemons such as
207 Check-point before user login services
211 as well as services which might run commands as users
217 Scripts that are to be sourced into the current shell rather than a subshell
221 Extreme care must be taken in using this, as the startup sequence will
222 terminate if the script does.
224 Scripts that are sourced in a subshell.
225 These can stop the boot if necessary with the following shell
227 .Bd -literal -offset indent
228 if [ "$autoboot" = yes ]; then
234 Note that this should be used extremely sparingly!
237 Each script should contain
239 keywords, especially an appropriate
241 entry, and if necessary
247 Each script is expected to support at least the following arguments, which
248 are automatically supported if it uses the
251 .Bl -tag -width ".Cm restart" -offset indent
254 This should check that the service is to be started as specified by
256 Also checks if the service is already running and refuses to start if
258 This latter check is not performed by standard
260 scripts if the system is starting directly to multi-user mode, to
261 speed up the boot process.
264 is given, skip the PID check.
269 check and start anyway.
271 If the service is to be started as specified by
274 This should check that the service is running and complain if it is not.
279 check and attempt to stop.
286 If the script starts a process (rather than performing a one-off
287 operation), show the status of the process.
288 Otherwise it is not necessary to support this argument.
289 Defaults to displaying the process ID of the program (if running).
291 If the script starts a process (rather than performing a one-off
292 operation), wait for the command to exit.
293 Otherwise it is not necessary to support this argument.
297 variables are used to control the startup of the service (if any).
300 If a script must implement additional commands it can list them in
303 variable, and define their actions in a variable constructed from
304 the command name (see the
308 The following key points apply to old-style scripts in
309 .Pa /usr/local/etc/rc.d/ :
312 Scripts are only executed if their
314 matches the shell globbing pattern
316 and they are executable.
317 Any other files or directories present within the directory are silently
320 When a script is executed at boot time, it is passed the string
322 as its only argument.
323 At shutdown time, it is passed the string
325 as its only argument.
328 scripts are expected to handle these arguments appropriately.
329 If no action needs to be taken at a given time
330 (either boot time or shutdown time),
331 the script should exit successfully and without producing an error message.
333 The scripts within each directory are executed in lexicographical order.
334 If a specific order is required,
335 numbers may be used as a prefix to the existing filenames,
338 would be executed before
340 without the numeric prefixes the opposite would be true.
342 The output from each script is traditionally a space character,
343 followed by the name of the software package being started or shut down,
345 a trailing newline character (see the
349 .Sh SCRIPTS OF INTEREST
350 When an automatic reboot is in progress,
352 is invoked with the argument
354 One of the scripts run from
366 file systems of minor inconsistencies resulting
367 from the last system shutdown.
368 If preening fails further action depends on the
386 is not set, when going from single-user to multi-user mode for example,
387 the script does not do anything.
390 .Pa /etc/rc.d/localdaemons
391 script can execute scripts from multiple
394 The default locations are
395 .Pa /usr/local/etc/rc.d/
397 .Pa /usr/pkg/etc/rc.d/ ,
398 but these may be overridden with the
405 script is used to set any special configurations for serial devices.
408 .Pa /etc/rc.d/{net*,routing}
409 scripts are used to start the network.
410 The network is started in several passes.
412 .Pa /etc/rc.d/netif ,
413 configures the network
416 .Pa /etc/rc.d/routing
417 script starts routing and sets routing options.
419 .Pa /etc/rc.d/netoptions
420 script sets additional networking options.
422 .Pa /etc/rc.d/network_ipv6
423 script configures IPv6 interfaces and options.
427 script is used to configure rules for the
429 kernel based firewall
431 It has several possible options:
433 .Bl -tag -width ".Ar filename" -compact -offset indent
437 will try to protect just this machine
439 will try to protect a whole network
441 totally disables IP services except via
445 disables the loading of firewall rules
447 will load the rules in the given filename (full path required).
450 Most daemons, including network related daemons, have their own script in
452 which can be used to start, stop, and check the status of the service.
454 Any architecture specific scripts, such as
456 for example, specifically check that they are on that architecture
457 before starting the daemon.
459 Following tradition, all startup files reside in
462 .Bl -tag -compact -width ".Pa /etc/rc.shutdown.local"
465 .It Pa /etc/rc.conf.local
467 .It Pa /etc/rc.firewall
469 .It Pa /etc/rc.shutdown
470 .It Pa /etc/rc.shutdown.local
474 The following is a minimal
477 Most scripts require little more than the following.
478 .Bd -literal -offset indent
483 # REQUIRE: bar_service_required_to_precede_foo
484 # BEFORE: baz_service_requiring_foo_to_precede_it
490 command="/usr/local/bin/foo"
496 Certain scripts may want to provide enhanced functionality.
497 The user may access this functionality through additional commands.
498 The script may list and define as many commands at it needs.
499 .Bd -literal -offset indent
504 # REQUIRE: bar_service_required_to_precede_foo
505 # BEFORE: baz_service_requiring_foo_to_precede_it
511 command="/usr/local/bin/foo"
512 extra_commands="nop hello"
513 hello_cmd="echo Hello World."
525 The following is a simple, hypothetical example of an old-style
526 .Pa /usr/local/etc/rc.d/
528 which would start a daemon at boot time,
529 and kill it at shutdown time.
530 .Bd -literal -offset indent
533 # initialization/shutdown script for foobar package
537 /usr/local/sbin/foo -d && echo -n ' foo'
540 kill `cat /var/run/foo.pid` && echo -n ' foo'
543 echo "unknown option: $1 - should be 'start' or 'stop'" >&2
548 As all processes are killed by
550 at shutdown, the explicit
552 is unnecessary, but is often included.
570 facility was implemented in