]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - share/man/man8/rc.8
Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.
[FreeBSD/stable/10.git] / share / man / man8 / rc.8
1 .\" Copyright (c) 1980, 1991, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Portions of this manual page are Copyrighted by
5 .\"     The NetBSD Foundation.
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
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.
22 .\"
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
33 .\" SUCH DAMAGE.
34 .\"
35 .\"     @(#)rc.8        8.2 (Berkeley) 12/11/93
36 .\" $FreeBSD$
37 .\"
38 .Dd September 23, 2013
39 .Dt RC 8
40 .Os
41 .Sh NAME
42 .Nm rc
43 .Nd command scripts for auto-reboot and daemon startup
44 .Sh SYNOPSIS
45 .Nm
46 .Nm rc.conf
47 .Nm rc.conf.local
48 .Nm rc.d/
49 .Nm rc.firewall
50 .Nm rc.local
51 .Nm rc.shutdown
52 .Nm rc.subr
53 .Sh DESCRIPTION
54 The
55 .Nm
56 utility is the command script which controls the automatic boot process
57 after being called by
58 .Xr init 8 .
59 The
60 .Nm rc.local
61 script contains commands which are pertinent only
62 to a specific site.
63 Typically, the
64 .Pa /usr/local/etc/rc.d/
65 mechanism is used instead of
66 .Nm rc.local
67 these days but if
68 you want to use
69 .Nm rc.local ,
70 it is still supported.
71 In this case, it should source
72 .Pa /etc/rc.conf
73 and contain additional custom startup code for your system.
74 The best way to handle
75 .Nm rc.local ,
76 however, is to separate it out into
77 .Nm rc.d/
78 style scripts and place them under
79 .Pa /usr/local/etc/rc.d/ .
80 The
81 .Nm rc.conf
82 file contains the global system configuration information referenced
83 by the startup scripts, while
84 .Nm rc.conf.local
85 contains the local system configuration.
86 See
87 .Xr rc.conf 5
88 for more information.
89 .Pp
90 The
91 .Nm rc.d/
92 directories contain scripts which will be automatically
93 executed at boot time and shutdown time.
94 .Ss Operation of Nm
95 .Bl -enum
96 .It
97 If autobooting, set
98 .Va autoboot Ns = Ns Li yes
99 and enable a flag
100 .Pq Va rc_fast Ns = Ns Li yes ,
101 which prevents the
102 .Nm rc.d/
103 scripts from performing the check for already running processes
104 (thus speeding up the boot process).
105 This
106 .Va rc_fast Ns = Ns Li yes
107 speedup will not occur when
108 .Nm
109 is started up after exiting the single-user shell.
110 .It
111 Determine whether the system is booting diskless,
112 and if so run the
113 .Pa /etc/rc.initdiskless
114 script.
115 .It
116 Source
117 .Pa /etc/rc.subr
118 to load various
119 .Xr rc.subr 8
120 shell functions to use.
121 .It
122 Load the configuration files.
123 .It
124 Determine if booting in a jail,
125 and add
126 .Dq Li nojail
127 (no jails allowed) or
128 .Dq Li nojailvnet
129 (only allow vnet-enabled jails) to the list of KEYWORDS to skip in
130 .Xr rcorder 8 .
131 .It
132 Invoke
133 .Xr rcorder 8
134 to order the files in
135 .Pa /etc/rc.d/
136 that do not have a
137 .Dq Li nostart
138 KEYWORD (refer to
139 .Xr rcorder 8 Ns 's
140 .Fl s
141 flag).
142 .It
143 Call each script in turn using
144 .Fn run_rc_script
145 (from
146 .Xr rc.subr 8 ) ,
147 which sets
148 .Va $1
149 to
150 .Dq Li start ,
151 and sources the script in a subshell.
152 If the script has a
153 .Pa .sh
154 suffix then it is sourced directly into the current shell.
155 Stop processing when the script that is the value of the
156 .Va $early_late_divider
157 has been run.
158 .It
159 Re-run
160 .Xr rcorder 8 ,
161 this time including the scripts in the
162 .Va $local_startup
163 directories.
164 Ignore everything up to the
165 .Va $early_late_divider ,
166 then start executing the scripts as described above.
167 .El
168 .Ss Operation of Nm rc.shutdown
169 .Bl -enum
170 .It
171 Source
172 .Pa /etc/rc.subr
173 to load various
174 .Xr rc.subr 8
175 shell functions to use.
176 .It
177 Load the configuration files.
178 .It
179 Invoke
180 .Xr rcorder 8
181 to order the files in
182 .Pa /etc/rc.d/
183 and the
184 .Va $local_startup
185 directories
186 that have a
187 .Dq Li shutdown
188 KEYWORD (refer to
189 .Xr rcorder 8 Ns 's
190 .Fl k
191 flag),
192 reverse that order, and assign the result to a variable.
193 .It
194 Call each script in turn using
195 .Fn run_rc_script
196 (from
197 .Xr rc.subr 8 ) ,
198 which sets
199 .Va $1
200 to
201 .Dq Li stop ,
202 and sources the script in a subshell.
203 If the script has a
204 .Pa .sh
205 suffix then it is sourced directly into the current shell.
206 .El
207 .Ss Contents of Nm rc.d/
208 .Nm rc.d/
209 is located in
210 .Pa /etc/rc.d/ .
211 The following file naming conventions are currently used in
212 .Nm rc.d/ :
213 .Bl -tag -width ".Pa ALLUPPERCASE" -offset indent
214 .It Pa ALLUPPERCASE
215 Scripts that are
216 .Dq placeholders
217 to ensure that certain operations are performed before others.
218 In order of startup, these are:
219 .Bl -tag -width ".Pa NETWORKING"
220 .It Pa NETWORKING
221 Ensure basic network services are running, including general
222 network configuration.
223 .It Pa SERVERS
224 Ensure basic services
225 exist for services that start early (such as
226 .Pa named ) ,
227 because they are required by
228 .Pa DAEMON
229 below.
230 .It Pa DAEMON
231 Check-point before all general purpose daemons such as
232 .Pa lpd
233 and
234 .Pa ntpd .
235 .It Pa LOGIN
236 Check-point before user login services
237 .Pa ( inetd
238 and
239 .Pa sshd ) ,
240 as well as services which might run commands as users
241 .Pa ( cron
242 and
243 .Pa sendmail ) .
244 .El
245 .It Pa foo.sh
246 Scripts that are to be sourced into the current shell rather than a subshell
247 have a
248 .Pa .sh
249 suffix.
250 Extreme care must be taken in using this, as the startup sequence will
251 terminate if the script does.
252 .It Pa bar
253 Scripts that are sourced in a subshell.
254 The boot does not stop if such a script terminates with a non-zero status,
255 but a script can stop the boot if necessary by invoking the
256 .Fn stop_boot
257 function (from
258 .Xr rc.subr 8 ) .
259 .El
260 .Pp
261 Each script should contain
262 .Xr rcorder 8
263 keywords, especially an appropriate
264 .Dq Li PROVIDE
265 entry, and if necessary
266 .Dq Li REQUIRE
267 and
268 .Dq Li BEFORE
269 keywords.
270 .Pp
271 Each script is expected to support at least the following arguments, which
272 are automatically supported if it uses the
273 .Fn run_rc_command
274 function:
275 .Bl -tag -width ".Cm restart" -offset indent
276 .It Cm start
277 Start the service.
278 This should check that the service is to be started as specified by
279 .Xr rc.conf 5 .
280 Also checks if the service is already running and refuses to start if
281 it is.
282 This latter check is not performed by standard
283 .Fx
284 scripts if the system is starting directly to multi-user mode, to
285 speed up the boot process.
286 If
287 .Cm forcestart
288 is given, ignore the
289 .Xr rc.conf 5
290 check and start anyway.
291 .It Cm stop
292 If the service is to be started as specified by
293 .Xr rc.conf 5 ,
294 stop the service.
295 This should check that the service is running and complain if it is not.
296 If
297 .Cm forcestop
298 is given, ignore the
299 .Xr rc.conf 5
300 check and attempt to stop.
301 .It Cm restart
302 Perform a
303 .Cm stop
304 then a
305 .Cm start .
306 .It Cm status
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).
311 .It Cm poll
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.
315 .It Cm enabled
316 Return 0 if the service is enabled and 1 if it is not.
317 This command does not print anything.
318 .It Cm rcvar
319 Display which
320 .Xr rc.conf 5
321 variables are used to control the startup of the service (if any).
322 .El
323 .Pp
324 If a script must implement additional commands it can list them in
325 the
326 .Va extra_commands
327 variable, and define their actions in a variable constructed from
328 the command name (see the
329 .Sx EXAMPLES
330 section).
331 .Pp
332 The following key points apply to old-style scripts in
333 .Pa /usr/local/etc/rc.d/ :
334 .Bl -bullet
335 .It
336 Scripts are only executed if their
337 .Xr basename 1
338 matches the shell globbing pattern
339 .Pa *.sh ,
340 and they are executable.
341 Any other files or directories present within the directory are silently
342 ignored.
343 .It
344 When a script is executed at boot time, it is passed the string
345 .Dq Li start
346 as its first and only argument.
347 At shutdown time, it is passed the string
348 .Dq Li stop
349 as its first and only argument.
350 All
351 .Nm rc.d/
352 scripts are expected to handle these arguments appropriately.
353 If no action needs to be taken at a given time
354 (either boot time or shutdown time),
355 the script should exit successfully and without producing an error message.
356 .It
357 The scripts within each directory are executed in lexicographical order.
358 If a specific order is required,
359 numbers may be used as a prefix to the existing filenames,
360 so for example
361 .Pa 100.foo
362 would be executed before
363 .Pa 200.bar ;
364 without the numeric prefixes the opposite would be true.
365 .It
366 The output from each script is traditionally a space character,
367 followed by the name of the software package being started or shut down,
368 .Em without
369 a trailing newline character (see the
370 .Sx EXAMPLES
371 section).
372 .El
373 .Sh SCRIPTS OF INTEREST
374 When an automatic reboot is in progress,
375 .Nm
376 is invoked with the argument
377 .Cm autoboot .
378 One of the scripts run from
379 .Pa /etc/rc.d/
380 is
381 .Pa /etc/rc.d/fsck .
382 This script runs
383 .Xr fsck 8
384 with option
385 .Fl p
386 and
387 .Fl F
388 to
389 .Dq preen
390 all the disks of minor inconsistencies resulting
391 from the last system shutdown.
392 If this fails, then checks/repairs of serious inconsistencies
393 caused by hardware or software failure will be performed
394 in the background at the end of the booting process.
395 If
396 .Cm autoboot
397 is not set, when going from single-user to multi-user mode for example,
398 the script does not do anything.
399 .Pp
400 The
401 .Pa /etc/rc.d/local
402 script can execute scripts from multiple
403 .Nm rc.d/
404 directories.
405 The default location includes
406 .Pa /usr/local/etc/rc.d/ ,
407 but these may be overridden with the
408 .Va local_startup
409 .Xr rc.conf 5
410 variable.
411 .Pp
412 The
413 .Pa /etc/rc.d/serial
414 script is used to set any special configurations for serial devices.
415 .Pp
416 The
417 .Nm rc.firewall
418 script is used to configure rules for the kernel based firewall
419 service.
420 It has several possible options:
421 .Pp
422 .Bl -tag -width ".Ar filename" -compact -offset indent
423 .It Cm open
424 will allow anyone in
425 .It Cm client
426 will try to protect just this machine
427 .It Cm simple
428 will try to protect a whole network
429 .It Cm closed
430 totally disables IP services except via
431 .Pa lo0
432 interface
433 .It Cm UNKNOWN
434 disables the loading of firewall rules
435 .It Ar filename
436 will load the rules in the given filename (full path required).
437 .El
438 .Pp
439 The
440 .Pa /etc/rc.d/atm*
441 scripts are used to configure ATM network interfaces.
442 The interfaces are configured in three passes.
443 The first pass performs the initial interface configuration.
444 The second pass completes the interface configuration and defines PVCs and
445 permanent ATMARP entries.
446 The third pass starts any ATM daemons.
447 .Pp
448 Most daemons, including network related daemons, have their own script in
449 .Pa /etc/rc.d/ ,
450 which can be used to start, stop, and check the status of the service.
451 .Pp
452 Any architecture specific scripts, such as
453 .Pa /etc/rc.d/apm
454 for example, specifically check that they are on that architecture
455 before starting the daemon.
456 .Pp
457 Following tradition, all startup files reside in
458 .Pa /etc .
459 .Sh FILES
460 .Bl -tag -compact -width Pa
461 .It Pa /etc/rc
462 .It Pa /etc/rc.conf
463 .It Pa /etc/rc.conf.local
464 .It Pa /etc/rc.d/
465 .It Pa /etc/rc.firewall
466 .It Pa /etc/rc.local
467 .It Pa /etc/rc.shutdown
468 .It Pa /etc/rc.subr
469 .It Pa /var/run/dmesg.boot
470 .Xr dmesg 8
471 results soon after the
472 .Nm
473 process begins.
474 Useful when
475 .Xr dmesg 8
476 buffer in the kernel no longer has this information.
477 .El
478 .Sh EXAMPLES
479 The following is a minimal
480 .Nm rc.d/
481 style script.
482 Most scripts require little more than the following.
483 .Bd -literal -offset indent
484 #!/bin/sh
485 #
486
487 # PROVIDE: foo
488 # REQUIRE: bar_service_required_to_precede_foo
489
490 \&. /etc/rc.subr
491
492 name="foo"
493 rcvar=foo_enable
494 command="/usr/local/bin/foo"
495
496 load_rc_config $name
497 run_rc_command "$1"
498 .Ed
499 .Pp
500 Certain scripts may want to provide enhanced functionality.
501 The user may access this functionality through additional commands.
502 The script may list and define as many commands at it needs.
503 .Bd -literal -offset indent
504 #!/bin/sh
505 #
506
507 # PROVIDE: foo
508 # REQUIRE: bar_service_required_to_precede_foo
509 # BEFORE:  baz_service_requiring_foo_to_precede_it
510
511 \&. /etc/rc.subr
512
513 name="foo"
514 rcvar=foo_enable
515 command="/usr/local/bin/foo"
516 extra_commands="nop hello"
517 hello_cmd="echo Hello World."
518 nop_cmd="do_nop"
519
520 do_nop()
521 {
522         echo "I do nothing."
523 }
524
525 load_rc_config $name
526 run_rc_command "$1"
527 .Ed
528 .Pp
529 As all processes are killed by
530 .Xr init 8
531 at shutdown, the explicit
532 .Xr kill 1
533 is unnecessary, but is often included.
534 .Sh SEE ALSO
535 .Xr kill 1 ,
536 .Xr rc.conf 5 ,
537 .Xr init 8 ,
538 .Xr rcorder 8 ,
539 .Xr rc.subr 8 ,
540 .Xr reboot 8 ,
541 .Xr savecore 8
542 .Sh HISTORY
543 The
544 .Nm
545 utility appeared in
546 .Bx 4.0 .