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