summaryrefslogtreecommitdiffstats
path: root/share/man/man8/rc.8
blob: b82da373dff11799ec0259555ff22f3d6e7ceb69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
.\" Copyright (c) 1980, 1991, 1993
.\"	The Regents of the University of California.  All rights reserved.
.\"
.\" Portions of this manual page are Copyrighted by
.\"	The NetBSD Foundation.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\"    must display the following acknowledgement:
.\"	This product includes software developed by the University of
.\"	California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\"    may be used to endorse or promote products derived from this software
.\"    without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\"     @(#)rc.8	8.2 (Berkeley) 12/11/93
.\" $FreeBSD$
.\"
.Dd November 4, 2002
.Dt RC 8
.Os
.Sh NAME
.Nm rc
.Nd command scripts for auto-reboot and daemon startup
.Sh SYNOPSIS
.Nm
.Nm rc.conf
.Nm rc.conf.local
.Nm rc.d/
.Nm rc.firewall
.Nm rc.local
.Nm rc.shutdown
.Nm rc.subr
.Sh DESCRIPTION
The
.Nm
utility is the command script which controls the automatic boot process
after being called by
.Xr init 8 .
The
.Nm rc.local
script contains commands which are pertinent only
to a specific site.
Typically, the
.Pa /usr/local/etc/rc.d/
mechanism is used instead of
.Nm rc.local
these days but if
you want to use
.Nm rc.local ,
it is still supported.
In this case, it should source
.Pa /etc/rc.conf
and contain additional custom startup code for your system.
The best way to handle
.Nm rc.local ,
however, is to separate it out into
.Nm rc.d/
style scripts and place them under
.Pa /usr/local/etc/rc.d/ .
The
.Nm rc.conf
file contains the global system configuration information referenced
by the startup scripts, while
.Nm rc.conf.local
contains the local system configuration.
See
.Xr rc.conf 5
for more information.
.Pp
The
.Nm rc.d/
directories contain scripts which will be automatically
executed at boot time and shutdown time.
.Ss Operation of Nm
.Bl -enum
.It
Source
.Pa /etc/rc.subr
to load various
.Xr rc.subr 8
shell functions to use.
.It
If autobooting, set
.Va autoboot Ns = Ns Li yes
and enable a flag
.Pq Va rc_fast Ns = Ns Li yes ,
which prevents the
.Nm rc.d/
scripts from performing the check for already running processes
(thus speeding up the boot process).
This
.Va rc_fast Ns = Ns Li yes
speedup will not occur when
.Nm
is started up after exiting the single-user shell.
.It
Invoke
.Xr rcorder 8
to order the files in
.Pa /etc/rc.d/
that do not have a
.Dq Li nostart
keyword (refer to
.Xr rcorder 8 Ns 's
.Fl s
flag),
and assign the result to a variable.
.It
Call each script in turn using
.Fn run_rc_script
(from
.Xr rc.subr 8 ) ,
which sets
.Va $1
to
.Dq Li start ,
and sources the script in a subshell.
If the script has a
.Pa .sh
suffix then it is sourced directly into the current shell.
.El
.Ss Operation of Nm rc.shutdown
.Bl -enum
.It
Source
.Pa /etc/rc.subr
to load various
.Xr rc.subr 8
shell functions to use.
.It
Invoke
.Xr rcorder 8
to order the files in
.Pa /etc/rc.d/
that have a
.Dq Li shutdown
keyword (refer to
.Xr rcorder 8 Ns 's
.Fl k
flag),
reverse that order, and assign the result to a variable.
.It
Call each script in turn using
.Fn run_rc_script
(from
.Xr rc.subr 8 ) ,
which sets
.Va $1
to
.Dq Li stop ,
and sources the script in a subshell.
If the script has a
.Pa .sh
suffix then it is sourced directly into the current shell.
.El
.Ss Contents of Nm rc.d/
.Nm rc.d/
is located in
.Pa /etc/rc.d/ .
The following file naming conventions are currently used in
.Nm rc.d/ :
.Bl -tag -width ".Pa ALLUPPERCASE" -offset indent
.It Pa ALLUPPERCASE
Scripts that are
.Dq placeholders
to ensure that certain operations are performed before others.
In order of startup, these are:
.Bl -tag -width ".Pa NETWORKING"
.It Pa NETWORKING
Ensure basic network services are running, including general
network configuration
.Pq Pa network1 , network2 , network3 .
.It Pa SERVERS
Ensure basic services (such as
.Pa NETWORKING , ppp-user , syslogd ,
and
.Pa isdnd )
exist for services that start early (such as
.Pa named ) ,
because they are required by
.Pa DAEMON
below.
.It Pa DAEMON
Check-point before all general purpose daemons such as
.Pa lpd
and
.Pa ntpd .
.It Pa LOGIN
Check-point before user login services
.Pa ( inetd
and
.Pa sshd ) ,
as well as services which might run commands as users
.Pa ( cron
and
.Pa sendmail ) .
.El
.It Pa foo.sh
Scripts that are to be sourced into the current shell rather than a subshell
have a
.Pa .sh
suffix.
Extreme care must be taken in using this, as the startup sequence will
terminate if the script does.
.It Pa bar
Scripts that are sourced in a subshell.
These can stop the boot if necessary with the following shell
commands:
.Bd -literal -offset indent
if [ "$autoboot" = yes ]; then
	kill -TERM $$
fi
exit 1
.Ed
.Pp
Note that this should be used extremely sparingly!
.El
.Pp
Each script should contain
.Xr rcorder 8
keywords, especially an appropriate
.Dq Li PROVIDE
entry, and if necessary
.Dq Li REQUIRE
and
.Dq Li BEFORE
keywords.
In addition, all scripts must have a
.Dq Li "# KEYWORD: FreeBSD"
line.
.Pp
Each script is expected to support at least the following arguments, which
are automatically supported if it uses the
.Fn run_rc_command
function:
.Bl -tag -width ".Cm restart" -offset indent
.It Cm start
Start the service.
This should check that the service is to be started as specified by
.Xr rc.conf 5 .
Also checks if the service is already running and refuses to start if
it is.
This latter check is not performed by standard
.Fx
scripts if the system is starting directly to multi-user mode, to
speed up the boot process.
If
.Cm forcestart
is given, ignore the
.Xr rc.conf 5
check and start anyway.
.It Cm stop
If the service is to be started as specified by
.Xr rc.conf 5 ,
stop the service.
This should check that the service is running and complain if it is not.
If
.Cm forcestop
is given, ignore the
.Xr rc.conf 5
check and attempt to stop.
.It Cm restart
Perform a
.Cm stop
then a
.Cm start .
.It Cm status
If the script starts a process (rather than performing a one-off
operation), show the status of the process.
Otherwise it is not necessary to support this argument.
Defaults to displaying the process ID of the program (if running).
.It Cm poll
If the script starts a process (rather than performing a one-off
operation), wait for the command to exit.
Otherwise it is not necessary to support this argument.
.It Cm rcvar
Display which
.Xr rc.conf 5
variables are used to control the startup of the service (if any).
.El
.Pp
If a script must implement additional commands it can list them in
the
.Va extra_commands
variable, and define their actions in a variable constructed from
the command name (see the
.Sx EXAMPLES
section).
.Pp
The following key points apply to old-style scripts in
.Pa /usr/local/etc/rc.d/ :
.Pp
.Bl -bullet
.It
Scripts are only executed if their
.Xr basename 1
matches the shell globbing pattern
.Pa *.sh ,
and they are executable.
Any other files or directories present within the directory are silently
ignored.
.It
When a script is executed at boot time, it is passed the string
.Dq Li start
as its first and only argument.
At shutdown time, it is passed the string
.Dq Li stop
as its first and only argument.
All
.Nm rc.d/
scripts are expected to handle these arguments appropriately.
If no action needs to be taken at a given time
(either boot time or shutdown time),
the script should exit successfully and without producing an error message.
.It
The scripts within each directory are executed in lexicographical order.
If a specific order is required,
numbers may be used as a prefix to the existing filenames,
so for example
.Pa 100.foo
would be executed before
.Pa 200.bar ;
without the numeric prefixes the opposite would be true.
.It
The output from each script is traditionally a space character,
followed by the name of the software package being started or shut down,
.Em without
a trailing newline character (see the
.Sx EXAMPLES
section).
.El
.Sh SCRIPTS OF INTEREST
When an automatic reboot is in progress,
.Nm
is invoked with the argument
.Cm autoboot .
One of the scripts run from
.Pa /etc/rc.d/
is
.Pa /etc/rc.d/fsck .
This script runs
.Xr fsck 8
with option
.Fl p
and
.Fl F
to
.Dq preen
all the disks of minor inconsistencies resulting
from the last system shutdown.
If this fails, then checks/repairs of serious inconsistencies
caused by hardware or software failure will be performed
in the background at the end of the booting process.
If
.Cm autoboot
is not set, when going from single-user to multi-user mode for example,
the script does not do anything.
.Pp
The
.Nm rc.early
script is run very early in the startup process, immediately before the
file system check.
The
.Nm rc.early
script is deprecated.
Any commands in this
file should be separated out into
.Nm rc.d/
style scripts and integrated into the
.Nm
system.
.Pp
The
.Pa /etc/rc.d/local
script can execute scripts from multiple
.Nm rc.d/
directories.
The default locations are
.Pa /usr/local/etc/rc.d/
and
.Pa /usr/X11R6/etc/rc.d/ ,
but these may be overridden with the
.Va local_startup
.Xr rc.conf 5
variable.
.Pp
The
.Pa /etc/rc.d/serial
script is used to set any special configurations for serial devices.
.Pp
The
.Pa /etc/rc.d/pccard
script is used to enable PC-cards.
.Pp
The
.Pa /etc/rc.d/network*
scripts are used to start the network.
The network is started in several passes.
The first pass,
.Pa /etc/rc.d/network1 ,
sets the hostname and domainname and configures the network
interfaces.
The
.Pa /etc/rc.d/network2
script starts routing and sets routing options.
The
.Pa /etc/rc.d/network3
script sets additional networking options.
Finally, the
.Pa /etc/rc.d/network_ipv6
script configures IPv6 interfaces and options.
.Pp
The
.Nm rc.firewall
script is used to configure rules for the kernel based firewall
service.
It has several possible options:
.Pp
.Bl -tag -width ".Ar filename" -compact -offset indent
.It Cm open
will allow anyone in
.It Cm client
will try to protect just this machine
.It Cm simple
will try to protect a whole network
.It Cm closed
totally disables IP services except via
.Pa lo0
interface
.It Cm UNKNOWN
disables the loading of firewall rules
.It Ar filename
will load the rules in the given filename (full path required).
.El
.Pp
The
.Pa /etc/rc.d/atm*
scripts are used to configure ATM network interfaces.
The interfaces are configured in three passes.
The first pass performs the initial interface configuration.
The second pass completes the interface configuration and defines PVCs and
permanent ATMARP entries.
The third pass starts any ATM daemons.
.Pp
Most daemons, including network related daemons, have their own script in
.Pa /etc/rc.d/ ,
which can be used to start, stop, and check the status of the service.
.Pp
Any architecture specific scripts, such as
.Pa /etc/rc.d/apm
for example, specifically check that they are on that architecture
before starting the daemon.
.Pp
Following tradition, all startup files reside in
.Pa /etc .
.Sh EXAMPLES
The following is a minimal
.Nm rc.d/
style script.
Most scripts require little more than the following.
.Bd -literal -offset indent
#!/bin/sh
#

# PROVIDE: foo
# REQUIRE: bar_service_required_to_precede_foo
# BEFORE:  baz_service_requiring_foo_to_precede_it
# KEYWORD: FreeBSD

\&. /etc/rc.subr

name="foo"
rcvar=`set_rcvar`
command="/usr/local/bin/foo"

load_rc_config $name
run_rc_command "$1"
.Ed
.Pp
Certain scripts may want to provide enhanced functionality.
The user may access this functionality through additional commands.
The script may list and define as many commands at it needs.
.Bd -literal -offset indent
#!/bin/sh
#

# PROVIDE: foo
# REQUIRE: bar_service_required_to_precede_foo
# BEFORE:  baz_service_requiring_foo_to_precede_it
# KEYWORD: FreeBSD

\&. /etc/rc.subr

name="foo"
rcvar=`set_rcvar`
command="/usr/local/bin/foo"
extra_commands="nop hello"
hello_cmd="echo Hello World."
nop_cmd="do_nop"

do_nop()
{
	echo "I do nothing."
}

load_rc_config $name
run_rc_command "$1"
.Ed
.Pp
The following is a simple, hypothetical example of an old-style
.Pa /usr/local/etc/rc.d/
script,
which would start a daemon at boot time,
and kill it at shutdown time.
.Bd -literal -offset indent
#!/bin/sh -
#
#    initialization/shutdown script for foobar package

case "$1" in
start)
	/usr/local/sbin/foo -d && echo -n ' foo'
	;;
stop)
	kill `cat /var/run/foo.pid` && echo -n ' foo'
	;;
*)
	echo "unknown option: $1 - should be 'start' or 'stop'" >&2
	;;
esac
.Ed
.Pp
As all processes are killed by
.Xr init 8
at shutdown, the explicit
.Xr kill 1
is unnecessary, but is often included.
.Sh FILES
.Bl -tag -compact
.It Pa /etc/rc
.It Pa /etc/rc.conf
.It Pa /etc/rc.conf.local
.It Pa /etc/rc.d/
.It Pa /etc/rc.firewall
.It Pa /etc/rc.local
.It Pa /etc/rc.shutdown
.It Pa /etc/rc.subr
.El
.Sh SEE ALSO
.Xr kill 1 ,
.Xr rc.conf 5 ,
.Xr init 8 ,
.Xr rc.subr 8 ,
.Xr rcorder 8 ,
.Xr reboot 8 ,
.Xr savecore 8
.Sh HISTORY
The
.Nm
utility appeared in
.Bx 4.0 .
OpenPOWER on IntegriCloud