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