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