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. All advertising materials mentioning features or use of this software
16 .\" must display the following acknowledgement:
17 .\" This product includes software developed by the University of
18 .\" California, Berkeley and its contributors.
19 .\" 4. Neither the name of the University nor the names of its contributors
20 .\" may be used to endorse or promote products derived from this software
21 .\" without specific prior written permission.
23 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 .\" @(#)rc.8 8.2 (Berkeley) 12/11/93
36 .\" $FreeBSD: src/share/man/man8/rc.8,v 1.22 2002/12/12 17:25:58 ru Exp $
37 .\" $DragonFly: src/share/man/man8/rc.8,v 1.7 2006/02/17 19:37:10 swildner Exp $
43 .Nd command scripts for auto-reboot and daemon startup
56 utility is the command script which controls the automatic boot process
61 script contains commands which are pertinent only
64 .Pa /usr/local/etc/rc.d/
65 mechanism is used instead of
70 it is still supported.
71 In this case, it should source
73 and contain additional custom startup code for your system.
74 The best way to handle
76 however, is to separate it out into
78 style scripts and place them under
79 .Pa /usr/local/etc/rc.d/ .
82 file contains the global system configuration information referenced
83 by the startup scripts, while
85 contains the local system configuration.
92 directories contain scripts which will be automatically
93 executed at boot time and shutdown time.
101 shell functions to use.
104 .Va autoboot Ns = Ns Li yes
106 .Pq Va rc_fast Ns = Ns Li yes ,
109 scripts from performing the check for already running processes
110 (thus speeding up the boot process).
112 .Va rc_fast Ns = Ns Li yes
113 speedup will not occur when
115 is started up after exiting the single-user shell.
119 to order the files in
127 and assign the result to a variable.
129 Call each script in turn using
137 and sources the script in a subshell.
140 suffix then it is sourced directly into the current shell.
142 .Ss Operation of Nm rc.shutdown
149 shell functions to use.
153 to order the files in
161 reverse that order, and assign the result to a variable.
163 Call each script in turn using
171 and sources the script in a subshell.
174 suffix then it is sourced directly into the current shell.
176 .Ss Contents of Nm rc.d/
180 The following file naming conventions are currently used in
182 .Bl -tag -width ".Pa ALLUPPERCASE" -offset indent
186 to ensure that certain operations are performed before others.
187 In order of startup, these are:
188 .Bl -tag -width ".Pa NETWORKING"
190 Ensure basic network services are running, including general
191 network configuration
192 .Pq Pa network1 , network2 , network3 .
194 Ensure basic services (such as
195 .Pa NETWORKING , ppp-user , syslogd ,
198 exist for services that start early (such as
200 because they are required by
204 Check-point before all general purpose daemons such as
209 Check-point before user login services
213 as well as services which might run commands as users
219 Scripts that are to be sourced into the current shell rather than a subshell
223 Extreme care must be taken in using this, as the startup sequence will
224 terminate if the script does.
226 Scripts that are sourced in a subshell.
227 These can stop the boot if necessary with the following shell
229 .Bd -literal -offset indent
230 if [ "$autoboot" = yes ]; then
236 Note that this should be used extremely sparingly!
239 Each script should contain
241 keywords, especially an appropriate
243 entry, and if necessary
249 Each script is expected to support at least the following arguments, which
250 are automatically supported if it uses the
253 .Bl -tag -width ".Cm restart" -offset indent
256 This should check that the service is to be started as specified by
258 Also checks if the service is already running and refuses to start if
260 This latter check is not performed by standard
262 scripts if the system is starting directly to multi-user mode, to
263 speed up the boot process.
268 check and start anyway.
270 If the service is to be started as specified by
273 This should check that the service is running and complain if it is not.
278 check and attempt to stop.
285 If the script starts a process (rather than performing a one-off
286 operation), show the status of the process.
287 Otherwise it is not necessary to support this argument.
288 Defaults to displaying the process ID of the program (if running).
290 If the script starts a process (rather than performing a one-off
291 operation), wait for the command to exit.
292 Otherwise it is not necessary to support this argument.
296 variables are used to control the startup of the service (if any).
299 If a script must implement additional commands it can list them in
302 variable, and define their actions in a variable constructed from
303 the command name (see the
307 The following key points apply to old-style scripts in
308 .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 first and only argument.
323 At shutdown time, it is passed the string
325 as its first and 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 all the disks of minor inconsistencies resulting
367 from the last system shutdown.
368 If this fails, then checks/repairs of serious inconsistencies
369 caused by hardware or software failure will be performed
370 in the background at the end of the booting process.
373 is not set, when going from single-user to multi-user mode for example,
374 the script does not do anything.
378 script is run very early in the startup process, immediately before the
382 script is deprecated.
384 file should be separated out into
386 style scripts and integrated into the
392 script can execute scripts from multiple
395 The default locations are
396 .Pa /usr/local/etc/rc.d/
398 .Pa /usr/X11R6/etc/rc.d/ ,
399 but these may be overridden with the
406 script is used to set any special configurations for serial devices.
409 .Pa /etc/rc.d/network*
410 scripts are used to start the network.
411 The network is started in several passes.
413 .Pa /etc/rc.d/network1 ,
414 sets the hostname and domainname and configures the network
417 .Pa /etc/rc.d/network2
418 script starts routing and sets routing options.
420 .Pa /etc/rc.d/network3
421 script sets additional networking options.
423 .Pa /etc/rc.d/network_ipv6
424 script configures IPv6 interfaces and options.
428 script is used to configure rules for the kernel based firewall
430 It has several possible options:
432 .Bl -tag -width ".Ar filename" -compact -offset indent
436 will try to protect just this machine
438 will try to protect a whole network
440 totally disables IP services except via
444 disables the loading of firewall rules
446 will load the rules in the given filename (full path required).
451 scripts are used to configure ATM network interfaces.
452 The interfaces are configured in three passes.
453 The first pass performs the initial interface configuration.
454 The second pass completes the interface configuration and defines PVCs and
455 permanent ATMARP entries.
456 The third pass starts any ATM daemons.
458 Most daemons, including network related daemons, have their own script in
460 which can be used to start, stop, and check the status of the service.
462 Any architecture specific scripts, such as
464 for example, specifically check that they are on that architecture
465 before starting the daemon.
467 Following tradition, all startup files reside in
473 .It Pa /etc/rc.conf.local
475 .It Pa /etc/rc.firewall
477 .It Pa /etc/rc.shutdown
481 The following is a minimal
484 Most scripts require little more than the following.
485 .Bd -literal -offset indent
490 # REQUIRE: bar_service_required_to_precede_foo
491 # BEFORE: baz_service_requiring_foo_to_precede_it
497 command="/usr/local/bin/foo"
503 Certain scripts may want to provide enhanced functionality.
504 The user may access this functionality through additional commands.
505 The script may list and define as many commands at it needs.
506 .Bd -literal -offset indent
511 # REQUIRE: bar_service_required_to_precede_foo
512 # BEFORE: baz_service_requiring_foo_to_precede_it
518 command="/usr/local/bin/foo"
519 extra_commands="nop hello"
520 hello_cmd="echo Hello World."
532 The following is a simple, hypothetical example of an old-style
533 .Pa /usr/local/etc/rc.d/
535 which would start a daemon at boot time,
536 and kill it at shutdown time.
537 .Bd -literal -offset indent
540 # initialization/shutdown script for foobar package
544 /usr/local/sbin/foo -d && echo -n ' foo'
547 kill `cat /var/run/foo.pid` && echo -n ' foo'
550 echo "unknown option: $1 - should be 'start' or 'stop'" >&2
555 As all processes are killed by
557 at shutdown, the explicit
559 is unnecessary, but is often included.