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.
118 to order the files in
126 and assign the result to a variable.
128 Call each script in turn using
136 and sources the script in a subshell.
139 suffix then it is sourced directly into the current shell.
141 .Ss Operation of Nm rc.shutdown
148 shell functions to use.
152 to order the files in
160 reverse that order, and assign the result to a variable.
162 Call each script in turn using
170 and sources the script in a subshell.
173 suffix then it is sourced directly into the current shell.
175 .Ss Contents of Nm rc.d/
179 The following file naming conventions are currently used in
181 .Bl -tag -width ".Pa ALLUPPERCASE" -offset indent
185 to ensure that certain operations are performed before others.
186 In order of startup, these are:
187 .Bl -tag -width ".Pa NETWORKING"
189 Ensure basic network services are running, including general
190 network configuration
191 .Pq Pa netif , routing , network_ipv6 , ppp .
193 Ensure basic services (such as
197 exist for services that start early (such as
199 because they are required by
203 Check-point before all general purpose daemons such as
208 Check-point before user login services
212 as well as services which might run commands as users
218 Scripts that are to be sourced into the current shell rather than a subshell
222 Extreme care must be taken in using this, as the startup sequence will
223 terminate if the script terminates.
225 Scripts that are sourced in a subshell.
226 These can stop the boot if necessary with the following shell
228 .Bd -literal -offset indent
229 if [ "$autoboot" = yes ]; then
235 Note that this should be used extremely sparingly!
238 Each script should contain
240 keywords, especially an appropriate
242 entry, and if necessary
248 Each script is expected to support at least the following arguments, which
249 are automatically supported if it uses the
252 .Bl -tag -width ".Cm restart" -offset indent
255 This should check that the service is to be started as specified by
257 Also checks if the service is already running and refuses to start if
259 This latter check is not performed by standard
261 scripts if the system is starting directly to multi-user mode, to
262 speed up the boot process.
265 is given, skip the PID check.
270 check and start anyway.
272 If the service is to be started as specified by
275 This should check that the service is running and complain if it is not.
280 check and attempt to stop.
291 to the program(s) associated with the service.
292 Note that not all scripts enable the
296 If the script starts a process (rather than performing a one-off
297 operation), show the status of the process.
298 Otherwise it is not necessary to support this argument.
299 Defaults to displaying the process ID of the program (if running).
301 If the script starts a process (rather than performing a one-off
302 operation), wait for the command to exit.
303 Otherwise it is not necessary to support this argument.
307 variables are used to control the startup of the service (if any).
310 If a script must implement additional commands it can list them in
313 variable, and define their actions in a variable constructed from
314 the command name (see the
318 The following key points apply to old-style scripts in
319 .Pa /usr/local/etc/rc.d/ :
322 Scripts are only executed if their
324 matches the shell globbing pattern
326 and they are executable.
327 Any other files or directories present within the directory are silently
330 When a script is executed at boot time, it is passed the string
332 as its only argument.
333 At shutdown time, it is passed the string
335 as its only argument.
338 scripts are expected to handle these arguments appropriately.
339 If no action needs to be taken at a given time
340 (either boot time or shutdown time),
341 the script should exit successfully and without producing an error message.
343 The scripts within each directory are executed in lexicographical order.
344 If a specific order is required,
345 numbers may be used as a prefix to the existing filenames,
348 would be executed before
350 without the numeric prefixes the opposite would be true.
352 The output from each script is traditionally a space character,
353 followed by the name of the software package being started or shut down,
355 a trailing newline character (see the
359 .Sh SCRIPTS OF INTEREST
360 When an automatic reboot is in progress,
362 is invoked with the argument
364 One of the scripts run from
376 file systems of minor inconsistencies resulting
377 from the last system shutdown.
378 If preening fails further action depends on the
396 is not set, when going from single-user to multi-user mode for example,
397 the script does not do anything.
400 .Pa /etc/rc.d/localdaemons
401 script can execute scripts from multiple
404 The default locations are
405 .Pa /usr/local/etc/rc.d/
407 .Pa /usr/pkg/etc/rc.d/ ,
408 but these may be overridden with the
415 script is used to set any special configurations for serial devices.
418 .Pa /etc/rc.d/{net*,routing}
419 scripts are used to start the network.
420 The network is started in several passes.
422 .Pa /etc/rc.d/netif ,
423 configures the network
426 .Pa /etc/rc.d/routing
427 script starts routing and sets routing options.
429 .Pa /etc/rc.d/netoptions
430 script sets additional networking options.
432 .Pa /etc/rc.d/network_ipv6
433 script configures IPv6 interfaces and options.
437 script is used to configure rules for the
439 kernel based firewall
441 It has several possible options:
443 .Bl -tag -width ".Ar filename" -compact -offset indent
447 will try to protect just this machine
449 will try to protect a whole network
451 totally disables IP services except via
455 disables the loading of firewall rules
457 will load the rules in the given filename (full path required).
460 Most daemons, including network related daemons, have their own script in
462 which can be used to start, stop, and check the status of the service.
464 Any architecture specific scripts, such as
465 specifically check that they are on that architecture
466 before starting the daemon.
468 Following tradition, all startup files reside in
471 .Bl -tag -compact -width ".Pa /etc/rc.shutdown.local"
474 .It Pa /etc/rc.conf.local
476 .It Pa /etc/rc.firewall
478 .It Pa /etc/rc.shutdown
479 .It Pa /etc/rc.shutdown.local
483 The following is a minimal
486 Most scripts require little more than the following.
487 .Bd -literal -offset indent
492 # REQUIRE: bar_service_required_to_precede_foo
493 # BEFORE: baz_service_requiring_foo_to_precede_it
499 command="/usr/local/bin/foo"
505 Certain scripts may want to provide enhanced functionality.
506 The user may access this functionality through additional commands.
507 The script may list and define as many commands at it needs.
508 .Bd -literal -offset indent
513 # REQUIRE: bar_service_required_to_precede_foo
514 # BEFORE: baz_service_requiring_foo_to_precede_it
520 command="/usr/local/bin/foo"
521 extra_commands="nop hello"
522 hello_cmd="echo Hello World."
534 The following is a simple, hypothetical example of an old-style
535 .Pa /usr/local/etc/rc.d/
537 which would start a daemon at boot time,
538 and kill it at shutdown time.
539 .Bd -literal -offset indent
542 # initialization/shutdown script for foobar package
546 /usr/local/sbin/foo -d && echo -n ' foo'
549 kill `cat /var/run/foo.pid` && echo -n ' foo'
552 echo "unknown option: $1 - should be 'start' or 'stop'" >&2
557 As all processes are killed by
559 at shutdown, the explicit
561 is unnecessary, but is often included.
579 facility was implemented in