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