xref: /freebsd/share/man/man8/rc.8 (revision d962d52ac03c57f733d9288c9656116651529f44)
1afe61c15SRodney W. Grimes.\" Copyright (c) 1980, 1991, 1993
2afe61c15SRodney W. Grimes.\"	The Regents of the University of California.  All rights reserved.
3afe61c15SRodney W. Grimes.\"
454e347fbSGordon Tetlow.\" Portions of this manual page are Copyrighted by
554e347fbSGordon Tetlow.\"	The NetBSD Foundation.
654e347fbSGordon Tetlow.\"
7afe61c15SRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without
8afe61c15SRodney W. Grimes.\" modification, are permitted provided that the following conditions
9afe61c15SRodney W. Grimes.\" are met:
10afe61c15SRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright
11afe61c15SRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer.
12afe61c15SRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright
13afe61c15SRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer in the
14afe61c15SRodney W. Grimes.\"    documentation and/or other materials provided with the distribution.
15afe61c15SRodney W. Grimes.\" 3. All advertising materials mentioning features or use of this software
16afe61c15SRodney W. Grimes.\"    must display the following acknowledgement:
17afe61c15SRodney W. Grimes.\"	This product includes software developed by the University of
18afe61c15SRodney W. Grimes.\"	California, Berkeley and its contributors.
19afe61c15SRodney W. Grimes.\" 4. Neither the name of the University nor the names of its contributors
20afe61c15SRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
21afe61c15SRodney W. Grimes.\"    without specific prior written permission.
22afe61c15SRodney W. Grimes.\"
23afe61c15SRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24afe61c15SRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25afe61c15SRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26afe61c15SRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27afe61c15SRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28afe61c15SRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29afe61c15SRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30afe61c15SRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31afe61c15SRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32afe61c15SRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33afe61c15SRodney W. Grimes.\" SUCH DAMAGE.
34afe61c15SRodney W. Grimes.\"
35afe61c15SRodney W. Grimes.\"     @(#)rc.8	8.2 (Berkeley) 12/11/93
367f3dea24SPeter Wemm.\" $FreeBSD$
37afe61c15SRodney W. Grimes.\"
3854e347fbSGordon Tetlow.Dd November 4, 2002
39afe61c15SRodney W. Grimes.Dt RC 8
403d45e180SRuslan Ermilov.Os
41afe61c15SRodney W. Grimes.Sh NAME
42afe61c15SRodney W. Grimes.Nm rc
43d962d52aSRuslan Ermilov.Nd command scripts for auto-reboot and daemon startup
44afe61c15SRodney W. Grimes.Sh SYNOPSIS
454b66483fSRuslan Ermilov.Nm
46e4f980d3SJordan K. Hubbard.Nm rc.conf
47e4f980d3SJordan K. Hubbard.Nm rc.conf.local
48d962d52aSRuslan Ermilov.Nm rc.d/
49e4f980d3SJordan K. Hubbard.Nm rc.firewall
50afe61c15SRodney W. Grimes.Nm rc.local
51e4f980d3SJordan K. Hubbard.Nm rc.shutdown
5254e347fbSGordon Tetlow.Nm rc.subr
53afe61c15SRodney W. Grimes.Sh DESCRIPTION
548d74f63dSPhilippe CharnierThe
558d74f63dSPhilippe Charnier.Nm
5654e347fbSGordon Tetlowutility is the command script which controls the automatic boot process
5754e347fbSGordon Tetlowafter being called by
5854e347fbSGordon Tetlow.Xr init 8 .
5954e347fbSGordon TetlowThe
60afe61c15SRodney W. Grimes.Nm rc.local
6154e347fbSGordon Tetlowscript contains commands which are pertinent only
62d962d52aSRuslan Ermilovto a specific site.
63d962d52aSRuslan ErmilovTypically, the
64d962d52aSRuslan Ermilov.Pa /usr/local/etc/rc.d/
6554e347fbSGordon Tetlowmechanism is used instead of
6654e347fbSGordon Tetlow.Nm rc.local
6754e347fbSGordon Tetlowthese days but if
6854e347fbSGordon Tetlowyou want to use
69d962d52aSRuslan Ermilov.Nm rc.local ,
70d962d52aSRuslan Ermilovit is still supported.
71d962d52aSRuslan ErmilovIn this case, it should source
72d962d52aSRuslan Ermilov.Pa /etc/rc.conf
7354e347fbSGordon Tetlowand contain additional custom startup code for your system.
7454e347fbSGordon TetlowThe best way to handle
75d962d52aSRuslan Ermilov.Nm rc.local ,
7654e347fbSGordon Tetlowhowever, is to separate it out into
77d962d52aSRuslan Ermilov.Nm rc.d/
78d962d52aSRuslan Ermilovstyle scripts and place them under
79d962d52aSRuslan Ermilov.Pa /usr/local/etc/rc.d/ .
808d74f63dSPhilippe CharnierThe
818d74f63dSPhilippe Charnier.Nm rc.conf
828d74f63dSPhilippe Charnierfile contains the global system configuration information referenced
8354e347fbSGordon Tetlowby the startup scripts, while
84e4f980d3SJordan K. Hubbard.Nm rc.conf.local
856575e6daSRuslan Ermilovcontains the local system configuration.
866575e6daSRuslan ErmilovSee
8754e347fbSGordon Tetlow.Xr rc.conf 5
8854e347fbSGordon Tetlowfor more information.
89e4f980d3SJordan K. Hubbard.Pp
9091e06c00SBen SmithurstThe
91d962d52aSRuslan Ermilov.Nm rc.d/
9291e06c00SBen Smithurstdirectories contain scripts which will be automatically
9391e06c00SBen Smithurstexecuted at boot time and shutdown time.
94d962d52aSRuslan Ermilov.Ss Operation of Nm
9554e347fbSGordon Tetlow.Bl -enum
9654e347fbSGordon Tetlow.It
9754e347fbSGordon TetlowSource
9854e347fbSGordon Tetlow.Pa /etc/rc.subr
9954e347fbSGordon Tetlowto load various
10054e347fbSGordon Tetlow.Xr rc.subr 8
10154e347fbSGordon Tetlowshell functions to use.
10254e347fbSGordon Tetlow.It
10354e347fbSGordon TetlowIf autobooting, set
104d962d52aSRuslan Ermilov.Va autoboot Ns = Ns Li yes
10554e347fbSGordon Tetlowand enable a flag
106d962d52aSRuslan Ermilov.Pq Va rc_fast Ns = Ns Li yes ,
10754e347fbSGordon Tetlowwhich prevents the
108d962d52aSRuslan Ermilov.Nm rc.d/
10954e347fbSGordon Tetlowscripts from performing the check for already running processes
11054e347fbSGordon Tetlow(thus speeding up the boot process).
11154e347fbSGordon TetlowThis
112d962d52aSRuslan Ermilov.Va rc_fast Ns = Ns Li yes
113d962d52aSRuslan Ermilovspeedup will not occur when
11454e347fbSGordon Tetlow.Nm
11554e347fbSGordon Tetlowis started up after exiting the single-user shell.
11654e347fbSGordon Tetlow.It
11754e347fbSGordon TetlowInvoke
11854e347fbSGordon Tetlow.Xr rcorder 8
11954e347fbSGordon Tetlowto order the files in
12054e347fbSGordon Tetlow.Pa /etc/rc.d/
12154e347fbSGordon Tetlowthat do not have a
122d962d52aSRuslan Ermilov.Dq Li nostart
12354e347fbSGordon Tetlowkeyword (refer to
124d962d52aSRuslan Ermilov.Xr rcorder 8 Ns 's
12554e347fbSGordon Tetlow.Fl s
12654e347fbSGordon Tetlowflag),
127d962d52aSRuslan Ermilovand assign the result to a variable.
12854e347fbSGordon Tetlow.It
129d962d52aSRuslan ErmilovCall each script in turn using
130d962d52aSRuslan Ermilov.Fn run_rc_script
131d962d52aSRuslan Ermilov(from
13254e347fbSGordon Tetlow.Xr rc.subr 8 ) ,
13354e347fbSGordon Tetlowwhich sets
134d962d52aSRuslan Ermilov.Va $1
13554e347fbSGordon Tetlowto
136d962d52aSRuslan Ermilov.Dq Li start ,
13754e347fbSGordon Tetlowand sources the script in a subshell.
13854e347fbSGordon TetlowIf the script has a
139d962d52aSRuslan Ermilov.Pa .sh
14054e347fbSGordon Tetlowsuffix then it is sourced directly into the current shell.
14154e347fbSGordon Tetlow.El
142d962d52aSRuslan Ermilov.Ss Operation of Nm rc.shutdown
14354e347fbSGordon Tetlow.Bl -enum
14454e347fbSGordon Tetlow.It
14554e347fbSGordon TetlowSource
14654e347fbSGordon Tetlow.Pa /etc/rc.subr
14754e347fbSGordon Tetlowto load various
14854e347fbSGordon Tetlow.Xr rc.subr 8
14954e347fbSGordon Tetlowshell functions to use.
15054e347fbSGordon Tetlow.It
15154e347fbSGordon TetlowInvoke
15254e347fbSGordon Tetlow.Xr rcorder 8
15354e347fbSGordon Tetlowto order the files in
15454e347fbSGordon Tetlow.Pa /etc/rc.d/
15554e347fbSGordon Tetlowthat have a
156d962d52aSRuslan Ermilov.Dq Li shutdown
15754e347fbSGordon Tetlowkeyword (refer to
158d962d52aSRuslan Ermilov.Xr rcorder 8 Ns 's
15954e347fbSGordon Tetlow.Fl k
16054e347fbSGordon Tetlowflag),
161d962d52aSRuslan Ermilovreverse that order, and assign the result to a variable.
16254e347fbSGordon Tetlow.It
163d962d52aSRuslan ErmilovCall each script in turn using
164d962d52aSRuslan Ermilov.Fn run_rc_script
165d962d52aSRuslan Ermilov(from
16654e347fbSGordon Tetlow.Xr rc.subr 8 ) ,
16754e347fbSGordon Tetlowwhich sets
168d962d52aSRuslan Ermilov.Va $1
16954e347fbSGordon Tetlowto
170d962d52aSRuslan Ermilov.Dq Li stop ,
17154e347fbSGordon Tetlowand sources the script in a subshell.
17254e347fbSGordon TetlowIf the script has a
173d962d52aSRuslan Ermilov.Pa .sh
17454e347fbSGordon Tetlowsuffix then it is sourced directly into the current shell.
17554e347fbSGordon Tetlow.El
176d962d52aSRuslan Ermilov.Ss Contents of Nm rc.d/
17754e347fbSGordon Tetlow.Nm rc.d/
17854e347fbSGordon Tetlowis located in
179d962d52aSRuslan Ermilov.Pa /etc/rc.d/ .
18054e347fbSGordon TetlowThe following file naming conventions are currently used in
18154e347fbSGordon Tetlow.Nm rc.d/ :
182d962d52aSRuslan Ermilov.Bl -tag -width ".Pa ALLUPPERCASE" -offset indent
18354e347fbSGordon Tetlow.It Pa ALLUPPERCASE
18454e347fbSGordon TetlowScripts that are
185d962d52aSRuslan Ermilov.Dq placeholders
18654e347fbSGordon Tetlowto ensure that certain operations are performed before others.
18754e347fbSGordon TetlowIn order of startup, these are:
188d962d52aSRuslan Ermilov.Bl -tag -width ".Pa NETWORKING"
18954e347fbSGordon Tetlow.It Pa NETWORKING
19054e347fbSGordon TetlowEnsure basic network services are running, including general
191d962d52aSRuslan Ermilovnetwork configuration
192d962d52aSRuslan Ermilov.Pq Pa network1 , network2 , network3 .
19354e347fbSGordon Tetlow.It Pa SERVERS
19454e347fbSGordon TetlowEnsure basic services (such as
195d962d52aSRuslan Ermilov.Pa NETWORKING , ppp-user , syslogd ,
19654e347fbSGordon Tetlowand
19754e347fbSGordon Tetlow.Pa isdnd )
19854e347fbSGordon Tetlowexist for services that start early (such as
19954e347fbSGordon Tetlow.Pa named ) ,
200d962d52aSRuslan Ermilovbecause they are required by
20154e347fbSGordon Tetlow.Pa DAEMON
20254e347fbSGordon Tetlowbelow.
20354e347fbSGordon Tetlow.It Pa DAEMON
20454e347fbSGordon TetlowCheck-point before all general purpose daemons such as
20554e347fbSGordon Tetlow.Pa lpd
20654e347fbSGordon Tetlowand
20754e347fbSGordon Tetlow.Pa ntpd .
20854e347fbSGordon Tetlow.It Pa LOGIN
20954e347fbSGordon TetlowCheck-point before user login services
21054e347fbSGordon Tetlow.Pa ( inetd
21154e347fbSGordon Tetlowand
21254e347fbSGordon Tetlow.Pa sshd ) ,
21354e347fbSGordon Tetlowas well as services which might run commands as users
21454e347fbSGordon Tetlow.Pa ( cron
21554e347fbSGordon Tetlowand
21654e347fbSGordon Tetlow.Pa sendmail ) .
21754e347fbSGordon Tetlow.El
21854e347fbSGordon Tetlow.It Pa foo.sh
21954e347fbSGordon TetlowScripts that are to be sourced into the current shell rather than a subshell
22054e347fbSGordon Tetlowhave a
221d962d52aSRuslan Ermilov.Pa .sh
22254e347fbSGordon Tetlowsuffix.
22354e347fbSGordon TetlowExtreme care must be taken in using this, as the startup sequence will
22454e347fbSGordon Tetlowterminate if the script does.
22554e347fbSGordon Tetlow.It Pa bar
22654e347fbSGordon TetlowScripts that are sourced in a subshell.
22754e347fbSGordon TetlowThese can stop the boot if necessary with the following shell
22854e347fbSGordon Tetlowcommands:
229d962d52aSRuslan Ermilov.Bd -literal -offset indent
23054e347fbSGordon Tetlowif [ "$autoboot" = yes ]; then
23154e347fbSGordon Tetlow	kill -TERM $$
23254e347fbSGordon Tetlowfi
23354e347fbSGordon Tetlowexit 1
23454e347fbSGordon Tetlow.Ed
23554e347fbSGordon Tetlow.Pp
23654e347fbSGordon TetlowNote that this should be used extremely sparingly!
23754e347fbSGordon Tetlow.El
23854e347fbSGordon Tetlow.Pp
23954e347fbSGordon TetlowEach script should contain
24054e347fbSGordon Tetlow.Xr rcorder 8
24154e347fbSGordon Tetlowkeywords, especially an appropriate
242d962d52aSRuslan Ermilov.Dq Li PROVIDE
24354e347fbSGordon Tetlowentry, and if necessary
244d962d52aSRuslan Ermilov.Dq Li REQUIRE
24554e347fbSGordon Tetlowand
246d962d52aSRuslan Ermilov.Dq Li BEFORE
247d962d52aSRuslan Ermilovkeywords.
248d962d52aSRuslan ErmilovIn addition, all scripts must have a
249d962d52aSRuslan Ermilov.Dq Li "# KEYWORD: FreeBSD"
25054e347fbSGordon Tetlowline.
25154e347fbSGordon Tetlow.Pp
25254e347fbSGordon TetlowEach script is expected to support at least the following arguments, which
253d962d52aSRuslan Ermilovare automatically supported if it uses the
254d962d52aSRuslan Ermilov.Fn run_rc_command
255d962d52aSRuslan Ermilovfunction:
256d962d52aSRuslan Ermilov.Bl -tag -width ".Cm restart" -offset indent
257d962d52aSRuslan Ermilov.It Cm start
25854e347fbSGordon TetlowStart the service.
25954e347fbSGordon TetlowThis should check that the service is to be started as specified by
26054e347fbSGordon Tetlow.Xr rc.conf 5 .
26154e347fbSGordon TetlowAlso checks if the service is already running and refuses to start if
26254e347fbSGordon Tetlowit is.
26354e347fbSGordon TetlowThis latter check is not performed by standard
26454e347fbSGordon Tetlow.Fx
26554e347fbSGordon Tetlowscripts if the system is starting directly to multi-user mode, to
26654e347fbSGordon Tetlowspeed up the boot process.
26754e347fbSGordon TetlowIf
268d962d52aSRuslan Ermilov.Cm forcestart
26954e347fbSGordon Tetlowis given, ignore the
27054e347fbSGordon Tetlow.Xr rc.conf 5
27154e347fbSGordon Tetlowcheck and start anyway.
272d962d52aSRuslan Ermilov.It Cm stop
27354e347fbSGordon TetlowIf the service is to be started as specified by
27454e347fbSGordon Tetlow.Xr rc.conf 5 ,
27554e347fbSGordon Tetlowstop the service.
276d962d52aSRuslan ErmilovThis should check that the service is running and complain if it is not.
27754e347fbSGordon TetlowIf
278d962d52aSRuslan Ermilov.Cm forcestop
27954e347fbSGordon Tetlowis given, ignore the
28054e347fbSGordon Tetlow.Xr rc.conf 5
28154e347fbSGordon Tetlowcheck and attempt to stop.
282d962d52aSRuslan Ermilov.It Cm restart
28354e347fbSGordon TetlowPerform a
284d962d52aSRuslan Ermilov.Cm stop
28554e347fbSGordon Tetlowthen a
286d962d52aSRuslan Ermilov.Cm start .
287d962d52aSRuslan Ermilov.It Cm status
28854e347fbSGordon TetlowIf the script starts a process (rather than performing a one-off
28954e347fbSGordon Tetlowoperation), show the status of the process.
290d962d52aSRuslan ErmilovOtherwise it is not necessary to support this argument.
29154e347fbSGordon TetlowDefaults to displaying the process ID of the program (if running).
292d962d52aSRuslan Ermilov.It Cm poll
29354e347fbSGordon TetlowIf the script starts a process (rather than performing a one-off
29454e347fbSGordon Tetlowoperation), wait for the command to exit.
295d962d52aSRuslan ErmilovOtherwise it is not necessary to support this argument.
296d962d52aSRuslan Ermilov.It Cm rcvar
29754e347fbSGordon TetlowDisplay which
29854e347fbSGordon Tetlow.Xr rc.conf 5
29954e347fbSGordon Tetlowvariables are used to control the startup of the service (if any).
30054e347fbSGordon Tetlow.El
30154e347fbSGordon Tetlow.Pp
30254e347fbSGordon TetlowIf a script must implement additional commands it can list them in
30354e347fbSGordon Tetlowthe
304d962d52aSRuslan Ermilov.Va extra_commands
305d962d52aSRuslan Ermilovvariable, and define their actions in a variable constructed from
30654e347fbSGordon Tetlowthe command name (see the
30754e347fbSGordon Tetlow.Sx EXAMPLES
30854e347fbSGordon Tetlowsection).
30954e347fbSGordon Tetlow.Pp
31054e347fbSGordon TetlowThe following key points apply to old-style scripts in
311d962d52aSRuslan Ermilov.Pa /usr/local/etc/rc.d/ :
31291e06c00SBen Smithurst.Pp
313d962d52aSRuslan Ermilov.Bl -bullet
31491e06c00SBen Smithurst.It
31591e06c00SBen SmithurstScripts are only executed if their
31691e06c00SBen Smithurst.Xr basename 1
31791e06c00SBen Smithurstmatches the shell globbing pattern
31891e06c00SBen Smithurst.Pa *.sh ,
31991e06c00SBen Smithurstand they are executable.
32091e06c00SBen SmithurstAny other files or directories present within the directory are silently
32191e06c00SBen Smithurstignored.
32291e06c00SBen Smithurst.It
32391e06c00SBen SmithurstWhen a script is executed at boot time, it is passed the string
324d962d52aSRuslan Ermilov.Dq Li start
32591e06c00SBen Smithurstas its first and only argument.
32691e06c00SBen SmithurstAt shutdown time, it is passed the string
327d962d52aSRuslan Ermilov.Dq Li stop
32891e06c00SBen Smithurstas its first and only argument.
32991e06c00SBen SmithurstAll
330d962d52aSRuslan Ermilov.Nm rc.d/
331d4bbfee2SJens Schweikhardtscripts are expected to handle these arguments appropriately.
33291e06c00SBen SmithurstIf no action needs to be taken at a given time
333d962d52aSRuslan Ermilov(either boot time or shutdown time),
33491e06c00SBen Smithurstthe script should exit successfully and without producing an error message.
33591e06c00SBen Smithurst.It
33691e06c00SBen SmithurstThe scripts within each directory are executed in lexicographical order.
33791e06c00SBen SmithurstIf a specific order is required,
33891e06c00SBen Smithurstnumbers may be used as a prefix to the existing filenames,
33991e06c00SBen Smithurstso for example
34091e06c00SBen Smithurst.Pa 100.foo
34191e06c00SBen Smithurstwould be executed before
34291e06c00SBen Smithurst.Pa 200.bar ;
34391e06c00SBen Smithurstwithout the numeric prefixes the opposite would be true.
34454e347fbSGordon Tetlow.It
34591e06c00SBen SmithurstThe output from each script is traditionally a space character,
34691e06c00SBen Smithurstfollowed by the name of the software package being started or shut down,
34791e06c00SBen Smithurst.Em without
34891e06c00SBen Smithursta trailing newline character (see the
34991e06c00SBen Smithurst.Sx EXAMPLES
35091e06c00SBen Smithurstsection).
35154e347fbSGordon Tetlow.El
352d962d52aSRuslan Ermilov.Sh SCRIPTS OF INTEREST
35354e347fbSGordon TetlowWhen an automatic reboot is in progress,
35454e347fbSGordon Tetlow.Nm
35554e347fbSGordon Tetlowis invoked with the argument
356d962d52aSRuslan Ermilov.Cm autoboot .
35754e347fbSGordon TetlowOne of the scripts run from
358d962d52aSRuslan Ermilov.Pa /etc/rc.d/
35954e347fbSGordon Tetlowis
36054e347fbSGordon Tetlow.Pa /etc/rc.d/fsck .
36154e347fbSGordon TetlowThis script runs
36254e347fbSGordon Tetlow.Xr fsck 8
36354e347fbSGordon Tetlowwith option
36454e347fbSGordon Tetlow.Fl p
36554e347fbSGordon Tetlowand
36654e347fbSGordon Tetlow.Fl F
367d962d52aSRuslan Ermilovto
368d962d52aSRuslan Ermilov.Dq preen
369d962d52aSRuslan Ermilovall the disks of minor inconsistencies resulting
370d962d52aSRuslan Ermilovfrom the last system shutdown.
371d962d52aSRuslan ErmilovIf this fails, then checks/repairs of serious inconsistencies
372d962d52aSRuslan Ermilovcaused by hardware or software failure will be performed
373d962d52aSRuslan Ermilovin the background at the end of the booting process.
374d962d52aSRuslan ErmilovIf
375d962d52aSRuslan Ermilov.Cm autoboot
376d962d52aSRuslan Ermilovis not set, when going from single-user to multi-user mode for example,
377d962d52aSRuslan Ermilovthe script does not do anything.
37891e06c00SBen Smithurst.Pp
37954e347fbSGordon TetlowThe
38054e347fbSGordon Tetlow.Nm rc.early
38154e347fbSGordon Tetlowscript is run very early in the startup process, immediately before the
382d962d52aSRuslan Ermilovfilesystem check.
383d962d52aSRuslan ErmilovThe
38454e347fbSGordon Tetlow.Nm rc.early
385d962d52aSRuslan Ermilovscript is deprecated.
386d962d52aSRuslan ErmilovAny commands in this
38754e347fbSGordon Tetlowfile should be separated out into
388d962d52aSRuslan Ermilov.Nm rc.d/
38954e347fbSGordon Tetlowstyle scripts and integrated into the
390d962d52aSRuslan Ermilov.Nm
39154e347fbSGordon Tetlowsystem.
39254e347fbSGordon Tetlow.Pp
39354e347fbSGordon TetlowThe
394d962d52aSRuslan Ermilov.Pa /etc/rc.d/local
39554e347fbSGordon Tetlowscript can execute scripts from multiple
396d962d52aSRuslan Ermilov.Nm rc.d/
39791e06c00SBen Smithurstdirectories.
39891e06c00SBen SmithurstThe default locations are
399d962d52aSRuslan Ermilov.Pa /usr/local/etc/rc.d/
40091e06c00SBen Smithurstand
401d962d52aSRuslan Ermilov.Pa /usr/X11R6/etc/rc.d/ ,
40291e06c00SBen Smithurstbut these may be overridden with the
40391e06c00SBen Smithurst.Va local_startup
40491e06c00SBen Smithurst.Xr rc.conf 5
40591e06c00SBen Smithurstvariable.
40691e06c00SBen Smithurst.Pp
4078d74f63dSPhilippe CharnierThe
408d962d52aSRuslan Ermilov.Pa /etc/rc.d/serial
4098d74f63dSPhilippe Charnierscript is used to set any special configurations for serial devices.
410afe61c15SRodney W. Grimes.Pp
4118d74f63dSPhilippe CharnierThe
412d962d52aSRuslan Ermilov.Pa /etc/rc.d/pccard
4138d74f63dSPhilippe Charnierscript is used to enable PC-cards.
414e4f980d3SJordan K. Hubbard.Pp
4158d74f63dSPhilippe CharnierThe
416d962d52aSRuslan Ermilov.Pa /etc/rc.d/network*
41754e347fbSGordon Tetlowscripts are used to start the network.
418d962d52aSRuslan ErmilovThe network is started in several passes.
41954e347fbSGordon TetlowThe first pass,
420d962d52aSRuslan Ermilov.Pa /etc/rc.d/network1 ,
42154e347fbSGordon Tetlowsets the hostname and domainname and configures the network
422d962d52aSRuslan Ermilovinterfaces.
423d962d52aSRuslan ErmilovThe
424d962d52aSRuslan Ermilov.Pa /etc/rc.d/network2
425d962d52aSRuslan Ermilovscript starts routing and sets routing options.
426d962d52aSRuslan ErmilovThe
427d962d52aSRuslan Ermilov.Pa /etc/rc.d/network3
428d962d52aSRuslan Ermilovscript sets additional networking options.
429d962d52aSRuslan ErmilovFinally, the
430d962d52aSRuslan Ermilov.Pa /etc/rc.d/network_ipv6
43154e347fbSGordon Tetlowscript configures IPv6 interfaces and options.
432e4f980d3SJordan K. Hubbard.Pp
4338d74f63dSPhilippe CharnierThe
4348d74f63dSPhilippe Charnier.Nm rc.firewall
4358d74f63dSPhilippe Charnierscript is used to configure rules for the kernel based firewall
4361111b49cSSheldon Hearnservice.
4371111b49cSSheldon HearnIt has several possible options:
438e4f980d3SJordan K. Hubbard.Pp
439d962d52aSRuslan Ermilov.Bl -tag -width ".Ar filename" -compact -offset indent
440d962d52aSRuslan Ermilov.It Cm open
441d962d52aSRuslan Ermilovwill allow anyone in
442d962d52aSRuslan Ermilov.It Cm client
443d962d52aSRuslan Ermilovwill try to protect just this machine
444d962d52aSRuslan Ermilov.It Cm simple
445d962d52aSRuslan Ermilovwill try to protect a whole network
446d962d52aSRuslan Ermilov.It Cm closed
447d962d52aSRuslan Ermilovtotally disables IP services except via
448d962d52aSRuslan Ermilov.Pa lo0
449d962d52aSRuslan Ermilovinterface
450d962d52aSRuslan Ermilov.It Cm UNKNOWN
451d962d52aSRuslan Ermilovdisables the loading of firewall rules
452d962d52aSRuslan Ermilov.It Ar filename
453e4f980d3SJordan K. Hubbardwill load the rules in the given filename (full path required).
454e4f980d3SJordan K. Hubbard.El
455e4f980d3SJordan K. Hubbard.Pp
4568d74f63dSPhilippe CharnierThe
457d962d52aSRuslan Ermilov.Pa /etc/rc.d/atm*
45854e347fbSGordon Tetlowscripts are used to configure ATM network interfaces.
4597d5c779cSPoul-Henning KampThe interfaces are configured in three passes.
4607d5c779cSPoul-Henning KampThe first pass performs the initial interface configuration.
4617d5c779cSPoul-Henning KampThe second pass completes the interface configuration and defines PVCs and
4627d5c779cSPoul-Henning Kamppermanent ATMARP entries.
4637d5c779cSPoul-Henning KampThe third pass starts any ATM daemons.
4647d5c779cSPoul-Henning Kamp.Pp
46554e347fbSGordon TetlowMost daemons, including network related daemons, have their own script in
466d962d52aSRuslan Ermilov.Pa /etc/rc.d/ ,
46754e347fbSGordon Tetlowwhich can be used to start, stop, and check the status of the service.
468e4f980d3SJordan K. Hubbard.Pp
46954e347fbSGordon TetlowAny architecture specific scripts, such as
47054e347fbSGordon Tetlow.Pa /etc/rc.d/apm
47154e347fbSGordon Tetlowfor example, specifically check that they are on that architecture
47254e347fbSGordon Tetlowbefore starting the daemon.
473e4f980d3SJordan K. Hubbard.Pp
47454e347fbSGordon TetlowFollowing tradition, all startup files reside in
475afe61c15SRodney W. Grimes.Pa /etc .
47691e06c00SBen Smithurst.Sh EXAMPLES
47754e347fbSGordon TetlowThe following is a minimal
478d962d52aSRuslan Ermilov.Nm rc.d/
479d962d52aSRuslan Ermilovstyle script.
480d962d52aSRuslan ErmilovMost scripts require little more than the following.
48154e347fbSGordon Tetlow.Bd -literal -offset indent
48254e347fbSGordon Tetlow#!/bin/sh
48354e347fbSGordon Tetlow#
48454e347fbSGordon Tetlow
48554e347fbSGordon Tetlow# PROVIDE: foo
48654e347fbSGordon Tetlow# REQUIRE: bar_service_required_to_precede_foo
48754e347fbSGordon Tetlow# BEFORE:  baz_service_requiring_foo_to_precede_it
48854e347fbSGordon Tetlow# KEYWORD: FreeBSD
48954e347fbSGordon Tetlow
490d962d52aSRuslan Ermilov\&. /etc/rc.subr
49154e347fbSGordon Tetlow
49254e347fbSGordon Tetlowname="foo"
49354e347fbSGordon Tetlowrcvar=`set_rcvar`
49454e347fbSGordon Tetlowcommand="/usr/local/bin/foo"
49554e347fbSGordon Tetlow
49654e347fbSGordon Tetlowload_rc_config $name
49754e347fbSGordon Tetlowrun_rc_command "$1"
49854e347fbSGordon Tetlow.Ed
49954e347fbSGordon Tetlow.Pp
500d962d52aSRuslan ErmilovCertain scripts may want to provide enhanced functionality.
501d962d52aSRuslan ErmilovThe user may access this functionality through additional commands.
502d962d52aSRuslan ErmilovThe script may list and define as many commands at it needs.
50354e347fbSGordon Tetlow.Bd -literal -offset indent
50454e347fbSGordon Tetlow#!/bin/sh
50554e347fbSGordon Tetlow#
50654e347fbSGordon Tetlow
50754e347fbSGordon Tetlow# PROVIDE: foo
50854e347fbSGordon Tetlow# REQUIRE: bar_service_required_to_precede_foo
50954e347fbSGordon Tetlow# BEFORE:  baz_service_requiring_foo_to_precede_it
51054e347fbSGordon Tetlow# KEYWORD: FreeBSD
51154e347fbSGordon Tetlow
512d962d52aSRuslan Ermilov\&. /etc/rc.subr
51354e347fbSGordon Tetlow
51454e347fbSGordon Tetlowname="foo"
51554e347fbSGordon Tetlowrcvar=`set_rcvar`
51654e347fbSGordon Tetlowcommand="/usr/local/bin/foo"
51754e347fbSGordon Tetlowextra_commands="nop hello"
51854e347fbSGordon Tetlowhello_cmd="echo Hello World."
51954e347fbSGordon Tetlownop_cmd="do_nop"
52054e347fbSGordon Tetlow
52154e347fbSGordon Tetlowdo_nop()
52254e347fbSGordon Tetlow{
52354e347fbSGordon Tetlow	echo "I do nothing."
52454e347fbSGordon Tetlow}
52554e347fbSGordon Tetlow
52654e347fbSGordon Tetlowload_rc_config $name
52754e347fbSGordon Tetlowrun_rc_command "$1"
52854e347fbSGordon Tetlow.Ed
52954e347fbSGordon Tetlow.Pp
53054e347fbSGordon TetlowThe following is a simple, hypothetical example of an old-style
531d962d52aSRuslan Ermilov.Pa /usr/local/etc/rc.d/
53291e06c00SBen Smithurstscript,
53391e06c00SBen Smithurstwhich would start a daemon at boot time,
53491e06c00SBen Smithurstand kill it at shutdown time.
53591e06c00SBen Smithurst.Bd -literal -offset indent
53691e06c00SBen Smithurst#!/bin/sh -
53791e06c00SBen Smithurst#
53891e06c00SBen Smithurst#    initialization/shutdown script for foobar package
53991e06c00SBen Smithurst
54091e06c00SBen Smithurstcase "$1" in
54191e06c00SBen Smithurststart)
54291e06c00SBen Smithurst	/usr/local/sbin/foo -d && echo -n ' foo'
54391e06c00SBen Smithurst	;;
54491e06c00SBen Smithurststop)
54591e06c00SBen Smithurst	kill `cat /var/run/foo.pid` && echo -n ' foo'
54691e06c00SBen Smithurst	;;
54791e06c00SBen Smithurst*)
54891e06c00SBen Smithurst	echo "unknown option: $1 - should be 'start' or 'stop'" >&2
54991e06c00SBen Smithurst	;;
55091e06c00SBen Smithurstesac
55191e06c00SBen Smithurst.Ed
55291e06c00SBen Smithurst.Pp
55391e06c00SBen SmithurstAs all processes are killed by
55491e06c00SBen Smithurst.Xr init 8
55591e06c00SBen Smithurstat shutdown, the explicit
55691e06c00SBen Smithurst.Xr kill 1
55791e06c00SBen Smithurstis unnecessary, but is often included.
558d962d52aSRuslan Ermilov.Sh FILES
559d962d52aSRuslan Ermilov.Bl -tag -compact
560d962d52aSRuslan Ermilov.It Pa /etc/rc
561d962d52aSRuslan Ermilov.It Pa /etc/rc.conf
562d962d52aSRuslan Ermilov.It Pa /etc/rc.conf.local
563d962d52aSRuslan Ermilov.It Pa /etc/rc.d/
564d962d52aSRuslan Ermilov.It Pa /etc/rc.firewall
565d962d52aSRuslan Ermilov.It Pa /etc/rc.local
566d962d52aSRuslan Ermilov.It Pa /etc/rc.shutdown
567d962d52aSRuslan Ermilov.It Pa /etc/rc.subr
568d962d52aSRuslan Ermilov.El
569afe61c15SRodney W. Grimes.Sh SEE ALSO
57091e06c00SBen Smithurst.Xr kill 1 ,
571e4f980d3SJordan K. Hubbard.Xr rc.conf 5 ,
572afe61c15SRodney W. Grimes.Xr init 8 ,
57354e347fbSGordon Tetlow.Xr rc.subr 8 ,
57454e347fbSGordon Tetlow.Xr rcorder 8 ,
575afe61c15SRodney W. Grimes.Xr reboot 8 ,
576afe61c15SRodney W. Grimes.Xr savecore 8
577afe61c15SRodney W. Grimes.Sh HISTORY
578afe61c15SRodney W. GrimesThe
579afe61c15SRodney W. Grimes.Nm
5808d74f63dSPhilippe Charnierutility appeared in
581afe61c15SRodney W. Grimes.Bx 4.0 .
582