xref: /freebsd/share/man/man8/rc.8 (revision 5fda0d60c1e004d6581f29c006635a51cee81349)
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.
15dda5b397SEitan Adler.\" 3. Neither the name of the University nor the names of its contributors
16afe61c15SRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
17afe61c15SRodney W. Grimes.\"    without specific prior written permission.
18afe61c15SRodney W. Grimes.\"
19afe61c15SRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20afe61c15SRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21afe61c15SRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22afe61c15SRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23afe61c15SRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24afe61c15SRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25afe61c15SRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26afe61c15SRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27afe61c15SRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28afe61c15SRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29afe61c15SRodney W. Grimes.\" SUCH DAMAGE.
30afe61c15SRodney W. Grimes.\"
31afe61c15SRodney W. Grimes.\"     @(#)rc.8	8.2 (Berkeley) 12/11/93
327f3dea24SPeter Wemm.\" $FreeBSD$
33afe61c15SRodney W. Grimes.\"
34bb66a3e9SMateusz Piotrowski.Dd September 6, 2019
35afe61c15SRodney W. Grimes.Dt RC 8
363d45e180SRuslan Ermilov.Os
37afe61c15SRodney W. Grimes.Sh NAME
38afe61c15SRodney W. Grimes.Nm rc
39d962d52aSRuslan Ermilov.Nd command scripts for auto-reboot and daemon startup
40afe61c15SRodney W. Grimes.Sh SYNOPSIS
414b66483fSRuslan Ermilov.Nm
42e4f980d3SJordan K. Hubbard.Nm rc.conf
43e4f980d3SJordan K. Hubbard.Nm rc.conf.local
44d962d52aSRuslan Ermilov.Nm rc.d/
45e4f980d3SJordan K. Hubbard.Nm rc.firewall
46afe61c15SRodney W. Grimes.Nm rc.local
47b25a469fSEugene Grosbein.Nm rc.resume
48e4f980d3SJordan K. Hubbard.Nm rc.shutdown
4954e347fbSGordon Tetlow.Nm rc.subr
50afe61c15SRodney W. Grimes.Sh DESCRIPTION
518d74f63dSPhilippe CharnierThe
528d74f63dSPhilippe Charnier.Nm
5354e347fbSGordon Tetlowutility is the command script which controls the automatic boot process
5454e347fbSGordon Tetlowafter being called by
5554e347fbSGordon Tetlow.Xr init 8 .
5654e347fbSGordon TetlowThe
57afe61c15SRodney W. Grimes.Nm rc.local
5854e347fbSGordon Tetlowscript contains commands which are pertinent only
59d962d52aSRuslan Ermilovto a specific site.
60d962d52aSRuslan ErmilovTypically, the
61d962d52aSRuslan Ermilov.Pa /usr/local/etc/rc.d/
6254e347fbSGordon Tetlowmechanism is used instead of
6354e347fbSGordon Tetlow.Nm rc.local
6454e347fbSGordon Tetlowthese days but if
6554e347fbSGordon Tetlowyou want to use
66d962d52aSRuslan Ermilov.Nm rc.local ,
67d962d52aSRuslan Ermilovit is still supported.
68d962d52aSRuslan ErmilovIn this case, it should source
69d962d52aSRuslan Ermilov.Pa /etc/rc.conf
7054e347fbSGordon Tetlowand contain additional custom startup code for your system.
7154e347fbSGordon TetlowThe best way to handle
72d962d52aSRuslan Ermilov.Nm rc.local ,
7354e347fbSGordon Tetlowhowever, is to separate it out into
74d962d52aSRuslan Ermilov.Nm rc.d/
75d962d52aSRuslan Ermilovstyle scripts and place them under
76d962d52aSRuslan Ermilov.Pa /usr/local/etc/rc.d/ .
778d74f63dSPhilippe CharnierThe
788d74f63dSPhilippe Charnier.Nm rc.conf
798d74f63dSPhilippe Charnierfile contains the global system configuration information referenced
8054e347fbSGordon Tetlowby the startup scripts, while
81e4f980d3SJordan K. Hubbard.Nm rc.conf.local
826575e6daSRuslan Ermilovcontains the local system configuration.
836575e6daSRuslan ErmilovSee
8454e347fbSGordon Tetlow.Xr rc.conf 5
8554e347fbSGordon Tetlowfor more information.
86e4f980d3SJordan K. Hubbard.Pp
8791e06c00SBen SmithurstThe
88d962d52aSRuslan Ermilov.Nm rc.d/
8991e06c00SBen Smithurstdirectories contain scripts which will be automatically
9091e06c00SBen Smithurstexecuted at boot time and shutdown time.
9109fdf1f8SStefan Eßer.Pp
92ce6c81b9SAndriy GaponThe
93ce6c81b9SAndriy Gapon.Xr service 8
9409b238e7SAndriy Gaponcommand provides a convenient interface to manage rc.d services.
95ce6c81b9SAndriy Gapon.Pp
96ce6c81b9SAndriy GaponThe
97ce6c81b9SAndriy Gapon.Xr sysrc 8
98ce6c81b9SAndriy Gaponcommand provides a scripting interface to modify system config files.
99d962d52aSRuslan Ermilov.Ss Operation of Nm
10054e347fbSGordon Tetlow.Bl -enum
10154e347fbSGordon Tetlow.It
10254e347fbSGordon TetlowIf autobooting, set
103d962d52aSRuslan Ermilov.Va autoboot Ns = Ns Li yes
10454e347fbSGordon Tetlowand enable a flag
105d962d52aSRuslan Ermilov.Pq Va rc_fast Ns = Ns Li yes ,
10654e347fbSGordon Tetlowwhich prevents the
107d962d52aSRuslan Ermilov.Nm rc.d/
10854e347fbSGordon Tetlowscripts from performing the check for already running processes
10954e347fbSGordon Tetlow(thus speeding up the boot process).
11054e347fbSGordon TetlowThis
111d962d52aSRuslan Ermilov.Va rc_fast Ns = Ns Li yes
112d962d52aSRuslan Ermilovspeedup will not occur when
11354e347fbSGordon Tetlow.Nm
11454e347fbSGordon Tetlowis started up after exiting the single-user shell.
11554e347fbSGordon Tetlow.It
1169eb99781SDoug BartonDetermine whether the system is booting diskless,
1179eb99781SDoug Bartonand if so run the
1189eb99781SDoug Barton.Pa /etc/rc.initdiskless
1199eb99781SDoug Bartonscript.
1209eb99781SDoug Barton.It
1219eb99781SDoug BartonSource
1229eb99781SDoug Barton.Pa /etc/rc.subr
1239eb99781SDoug Bartonto load various
1249eb99781SDoug Barton.Xr rc.subr 8
1259eb99781SDoug Bartonshell functions to use.
1269eb99781SDoug Barton.It
1279eb99781SDoug BartonLoad the configuration files.
1289eb99781SDoug Barton.It
1299eb99781SDoug BartonDetermine if booting in a jail,
1309eb99781SDoug Bartonand add
13181ae4b8dSRuslan Ermilov.Dq Li nojail
1326a774190SJamie Gritton(no jails allowed) or
1336a774190SJamie Gritton.Dq Li nojailvnet
1346a774190SJamie Gritton(only allow vnet-enabled jails) to the list of KEYWORDS to skip in
1359eb99781SDoug Barton.Xr rcorder 8 .
1369eb99781SDoug Barton.It
137cabad264SColin PercivalIf the file
138cabad264SColin Percival.Va ${firstboot_sentinel}
139cabad264SColin Percivaldoes not exist, add
140cabad264SColin Percival.Dq Li firstboot
141cabad264SColin Percivalto the list of KEYWORDS to skip in
142cabad264SColin Percival.Xr rcorder 8 .
143cabad264SColin Percival.It
14454e347fbSGordon TetlowInvoke
14554e347fbSGordon Tetlow.Xr rcorder 8
14654e347fbSGordon Tetlowto order the files in
14754e347fbSGordon Tetlow.Pa /etc/rc.d/
14854e347fbSGordon Tetlowthat do not have a
149d962d52aSRuslan Ermilov.Dq Li nostart
1509eb99781SDoug BartonKEYWORD (refer to
151d962d52aSRuslan Ermilov.Xr rcorder 8 Ns 's
15254e347fbSGordon Tetlow.Fl s
1539eb99781SDoug Bartonflag).
15454e347fbSGordon Tetlow.It
155d962d52aSRuslan ErmilovCall each script in turn using
156d962d52aSRuslan Ermilov.Fn run_rc_script
157d962d52aSRuslan Ermilov(from
15854e347fbSGordon Tetlow.Xr rc.subr 8 ) ,
15954e347fbSGordon Tetlowwhich sets
160d962d52aSRuslan Ermilov.Va $1
16154e347fbSGordon Tetlowto
162d962d52aSRuslan Ermilov.Dq Li start ,
16354e347fbSGordon Tetlowand sources the script in a subshell.
1649eb99781SDoug BartonStop processing when the script that is the value of the
1659eb99781SDoug Barton.Va $early_late_divider
1669eb99781SDoug Bartonhas been run.
1679eb99781SDoug Barton.It
168cabad264SColin PercivalCheck again to see if the file
169cabad264SColin Percival.Va ${firstboot_sentinel}
170cabad264SColin Percivalexists (in case it is located on a newly mounted file system)
171cabad264SColin Percivaland adjust the list of KEYWORDs to skip appropriately.
172cabad264SColin Percival.It
1739eb99781SDoug BartonRe-run
1749eb99781SDoug Barton.Xr rcorder 8 ,
1759eb99781SDoug Bartonthis time including the scripts in the
1769eb99781SDoug Barton.Va $local_startup
1779eb99781SDoug Bartondirectories.
1789eb99781SDoug BartonIgnore everything up to the
1799eb99781SDoug Barton.Va $early_late_divider ,
1809eb99781SDoug Bartonthen start executing the scripts as described above.
181cabad264SColin Percival.It
182cabad264SColin PercivalIf the file
183cabad264SColin Percival.Va ${firstboot_sentinel}
184cabad264SColin Percivalexists, delete it.
185cabad264SColin PercivalIf the file
186cabad264SColin Percival.Va ${firstboot_sentinel}-reboot
187cabad264SColin Percivalalso exists (because it was created by a script), then delete it and reboot.
18854e347fbSGordon Tetlow.El
189d962d52aSRuslan Ermilov.Ss Operation of Nm rc.shutdown
19054e347fbSGordon Tetlow.Bl -enum
19154e347fbSGordon Tetlow.It
192*5fda0d60SAndriy GaponSet
193*5fda0d60SAndriy Gapon.Va rc_shutdown
194*5fda0d60SAndriy Gaponto the value of the first argument passed to
195*5fda0d60SAndriy Gapon.Nm rc.shutdown
196*5fda0d60SAndriy Gaponor to
197*5fda0d60SAndriy Gapon.Dq Li unspecified
198*5fda0d60SAndriy Gaponif no argument was passed.
199*5fda0d60SAndriy Gapon.It
20054e347fbSGordon TetlowSource
20154e347fbSGordon Tetlow.Pa /etc/rc.subr
20254e347fbSGordon Tetlowto load various
20354e347fbSGordon Tetlow.Xr rc.subr 8
20454e347fbSGordon Tetlowshell functions to use.
20554e347fbSGordon Tetlow.It
2069eb99781SDoug BartonLoad the configuration files.
2079eb99781SDoug Barton.It
20854e347fbSGordon TetlowInvoke
20954e347fbSGordon Tetlow.Xr rcorder 8
21054e347fbSGordon Tetlowto order the files in
21154e347fbSGordon Tetlow.Pa /etc/rc.d/
2129eb99781SDoug Bartonand the
2139eb99781SDoug Barton.Va $local_startup
2149eb99781SDoug Bartondirectories
21554e347fbSGordon Tetlowthat have a
216d962d52aSRuslan Ermilov.Dq Li shutdown
2179eb99781SDoug BartonKEYWORD (refer to
218d962d52aSRuslan Ermilov.Xr rcorder 8 Ns 's
21954e347fbSGordon Tetlow.Fl k
22054e347fbSGordon Tetlowflag),
221d962d52aSRuslan Ermilovreverse that order, and assign the result to a variable.
22254e347fbSGordon Tetlow.It
223d962d52aSRuslan ErmilovCall each script in turn using
224d962d52aSRuslan Ermilov.Fn run_rc_script
225d962d52aSRuslan Ermilov(from
22654e347fbSGordon Tetlow.Xr rc.subr 8 ) ,
22754e347fbSGordon Tetlowwhich sets
228d962d52aSRuslan Ermilov.Va $1
22954e347fbSGordon Tetlowto
230ce6c81b9SAndriy Gapon.Dq Li faststop ,
23154e347fbSGordon Tetlowand sources the script in a subshell.
23254e347fbSGordon Tetlow.El
233d962d52aSRuslan Ermilov.Ss Contents of Nm rc.d/
23454e347fbSGordon Tetlow.Nm rc.d/
23554e347fbSGordon Tetlowis located in
236d962d52aSRuslan Ermilov.Pa /etc/rc.d/ .
23754e347fbSGordon TetlowThe following file naming conventions are currently used in
23854e347fbSGordon Tetlow.Nm rc.d/ :
239d962d52aSRuslan Ermilov.Bl -tag -width ".Pa ALLUPPERCASE" -offset indent
24054e347fbSGordon Tetlow.It Pa ALLUPPERCASE
24154e347fbSGordon TetlowScripts that are
242d962d52aSRuslan Ermilov.Dq placeholders
24354e347fbSGordon Tetlowto ensure that certain operations are performed before others.
24454e347fbSGordon TetlowIn order of startup, these are:
245d962d52aSRuslan Ermilov.Bl -tag -width ".Pa NETWORKING"
24654e347fbSGordon Tetlow.It Pa NETWORKING
24754e347fbSGordon TetlowEnsure basic network services are running, including general
2489eb99781SDoug Bartonnetwork configuration.
24954e347fbSGordon Tetlow.It Pa SERVERS
2509eb99781SDoug BartonEnsure basic services
25154e347fbSGordon Tetlowexist for services that start early (such as
25254c22eeaSSergey Kandaurov.Pa nisdomain ) ,
253d962d52aSRuslan Ermilovbecause they are required by
25454e347fbSGordon Tetlow.Pa DAEMON
25554e347fbSGordon Tetlowbelow.
25654e347fbSGordon Tetlow.It Pa DAEMON
25754e347fbSGordon TetlowCheck-point before all general purpose daemons such as
25854e347fbSGordon Tetlow.Pa lpd
25954e347fbSGordon Tetlowand
26054e347fbSGordon Tetlow.Pa ntpd .
26154e347fbSGordon Tetlow.It Pa LOGIN
26254e347fbSGordon TetlowCheck-point before user login services
26354e347fbSGordon Tetlow.Pa ( inetd
26454e347fbSGordon Tetlowand
26554e347fbSGordon Tetlow.Pa sshd ) ,
26654e347fbSGordon Tetlowas well as services which might run commands as users
26754e347fbSGordon Tetlow.Pa ( cron
26854e347fbSGordon Tetlowand
26954e347fbSGordon Tetlow.Pa sendmail ) .
27054e347fbSGordon Tetlow.El
27154e347fbSGordon Tetlow.It Pa bar
27254e347fbSGordon TetlowScripts that are sourced in a subshell.
2733d03791bSMike MakonnenThe boot does not stop if such a script terminates with a non-zero status,
2743d03791bSMike Makonnenbut a script can stop the boot if necessary by invoking the
2753d03791bSMike Makonnen.Fn stop_boot
2763d03791bSMike Makonnenfunction (from
2773d03791bSMike Makonnen.Xr rc.subr 8 ) .
27854e347fbSGordon Tetlow.El
27954e347fbSGordon Tetlow.Pp
28054e347fbSGordon TetlowEach script should contain
28154e347fbSGordon Tetlow.Xr rcorder 8
28254e347fbSGordon Tetlowkeywords, especially an appropriate
283d962d52aSRuslan Ermilov.Dq Li PROVIDE
28454e347fbSGordon Tetlowentry, and if necessary
285d962d52aSRuslan Ermilov.Dq Li REQUIRE
28654e347fbSGordon Tetlowand
287d962d52aSRuslan Ermilov.Dq Li BEFORE
288d962d52aSRuslan Ermilovkeywords.
28954e347fbSGordon Tetlow.Pp
29054e347fbSGordon TetlowEach script is expected to support at least the following arguments, which
291d962d52aSRuslan Ermilovare automatically supported if it uses the
292d962d52aSRuslan Ermilov.Fn run_rc_command
293d962d52aSRuslan Ermilovfunction:
294d962d52aSRuslan Ermilov.Bl -tag -width ".Cm restart" -offset indent
295d962d52aSRuslan Ermilov.It Cm start
29654e347fbSGordon TetlowStart the service.
29754e347fbSGordon TetlowThis should check that the service is to be started as specified by
29854e347fbSGordon Tetlow.Xr rc.conf 5 .
29954e347fbSGordon TetlowAlso checks if the service is already running and refuses to start if
30054e347fbSGordon Tetlowit is.
30154e347fbSGordon TetlowThis latter check is not performed by standard
30254e347fbSGordon Tetlow.Fx
30354e347fbSGordon Tetlowscripts if the system is starting directly to multi-user mode, to
30454e347fbSGordon Tetlowspeed up the boot process.
30554e347fbSGordon TetlowIf
306d962d52aSRuslan Ermilov.Cm forcestart
30754e347fbSGordon Tetlowis given, ignore the
30854e347fbSGordon Tetlow.Xr rc.conf 5
30954e347fbSGordon Tetlowcheck and start anyway.
310d962d52aSRuslan Ermilov.It Cm stop
31154e347fbSGordon TetlowIf the service is to be started as specified by
31254e347fbSGordon Tetlow.Xr rc.conf 5 ,
31354e347fbSGordon Tetlowstop the service.
314d962d52aSRuslan ErmilovThis should check that the service is running and complain if it is not.
31554e347fbSGordon TetlowIf
316d962d52aSRuslan Ermilov.Cm forcestop
31754e347fbSGordon Tetlowis given, ignore the
31854e347fbSGordon Tetlow.Xr rc.conf 5
31954e347fbSGordon Tetlowcheck and attempt to stop.
320d962d52aSRuslan Ermilov.It Cm restart
32154e347fbSGordon TetlowPerform a
322d962d52aSRuslan Ermilov.Cm stop
32354e347fbSGordon Tetlowthen a
324d962d52aSRuslan Ermilov.Cm start .
325d962d52aSRuslan Ermilov.It Cm status
32654e347fbSGordon TetlowIf the script starts a process (rather than performing a one-off
32754e347fbSGordon Tetlowoperation), show the status of the process.
328d962d52aSRuslan ErmilovOtherwise it is not necessary to support this argument.
32954e347fbSGordon TetlowDefaults to displaying the process ID of the program (if running).
330da45b4daSDevin Teske.It Cm enable
331da45b4daSDevin TeskeEnable the service in
332da45b4daSDevin Teske.Xr rc.conf 5 .
333da45b4daSDevin Teske.It Cm disable
334da45b4daSDevin TeskeDisable the service in
335da45b4daSDevin Teske.Xr rc.conf 5 .
336da45b4daSDevin Teske.It Cm delete
337da45b4daSDevin TeskeRemove the service from
338da45b4daSDevin Teske.Xr rc.conf 5 .
339da45b4daSDevin TeskeIf
340da45b4daSDevin Teske.Ql Li service_delete_empty
341da45b4daSDevin Teskeis set to
342da45b4daSDevin Teske.Dq Li YES ,
343da45b4daSDevin Teske.Pa /etc/rc.conf.d/$servicename
344da45b4daSDevin Teskewill be deleted if empty after modification.
3451980d11bSLars Engels.It Cm describe
3461980d11bSLars EngelsPrint a short description of what the script does.
3471980d11bSLars Engels.It Cm extracommands
3481980d11bSLars EngelsPrint the script's non-standard commands.
349d962d52aSRuslan Ermilov.It Cm poll
35054e347fbSGordon TetlowIf the script starts a process (rather than performing a one-off
35154e347fbSGordon Tetlowoperation), wait for the command to exit.
352d962d52aSRuslan ErmilovOtherwise it is not necessary to support this argument.
35349cede74SDag-Erling Smørgrav.It Cm enabled
35449cede74SDag-Erling SmørgravReturn 0 if the service is enabled and 1 if it is not.
35549cede74SDag-Erling SmørgravThis command does not print anything.
356d962d52aSRuslan Ermilov.It Cm rcvar
35754e347fbSGordon TetlowDisplay which
35854e347fbSGordon Tetlow.Xr rc.conf 5
35954e347fbSGordon Tetlowvariables are used to control the startup of the service (if any).
36054e347fbSGordon Tetlow.El
36154e347fbSGordon Tetlow.Pp
36254e347fbSGordon TetlowIf a script must implement additional commands it can list them in
36354e347fbSGordon Tetlowthe
364d962d52aSRuslan Ermilov.Va extra_commands
365d962d52aSRuslan Ermilovvariable, and define their actions in a variable constructed from
36654e347fbSGordon Tetlowthe command name (see the
36754e347fbSGordon Tetlow.Sx EXAMPLES
36854e347fbSGordon Tetlowsection).
36954e347fbSGordon Tetlow.Pp
37054e347fbSGordon TetlowThe following key points apply to old-style scripts in
371d962d52aSRuslan Ermilov.Pa /usr/local/etc/rc.d/ :
372d962d52aSRuslan Ermilov.Bl -bullet
37391e06c00SBen Smithurst.It
37491e06c00SBen SmithurstScripts are only executed if their
37591e06c00SBen Smithurst.Xr basename 1
37691e06c00SBen Smithurstmatches the shell globbing pattern
37791e06c00SBen Smithurst.Pa *.sh ,
37891e06c00SBen Smithurstand they are executable.
37991e06c00SBen SmithurstAny other files or directories present within the directory are silently
38091e06c00SBen Smithurstignored.
38191e06c00SBen Smithurst.It
38291e06c00SBen SmithurstWhen a script is executed at boot time, it is passed the string
383d962d52aSRuslan Ermilov.Dq Li start
38491e06c00SBen Smithurstas its first and only argument.
38591e06c00SBen SmithurstAt shutdown time, it is passed the string
386d962d52aSRuslan Ermilov.Dq Li stop
38791e06c00SBen Smithurstas its first and only argument.
38891e06c00SBen SmithurstAll
389d962d52aSRuslan Ermilov.Nm rc.d/
390d4bbfee2SJens Schweikhardtscripts are expected to handle these arguments appropriately.
39191e06c00SBen SmithurstIf no action needs to be taken at a given time
392d962d52aSRuslan Ermilov(either boot time or shutdown time),
39391e06c00SBen Smithurstthe script should exit successfully and without producing an error message.
39491e06c00SBen Smithurst.It
39591e06c00SBen SmithurstThe scripts within each directory are executed in lexicographical order.
39691e06c00SBen SmithurstIf a specific order is required,
39791e06c00SBen Smithurstnumbers may be used as a prefix to the existing filenames,
39891e06c00SBen Smithurstso for example
39991e06c00SBen Smithurst.Pa 100.foo
40091e06c00SBen Smithurstwould be executed before
40191e06c00SBen Smithurst.Pa 200.bar ;
40291e06c00SBen Smithurstwithout the numeric prefixes the opposite would be true.
40354e347fbSGordon Tetlow.It
40491e06c00SBen SmithurstThe output from each script is traditionally a space character,
40591e06c00SBen Smithurstfollowed by the name of the software package being started or shut down,
40691e06c00SBen Smithurst.Em without
407bb66a3e9SMateusz Piotrowskia trailing newline character.
40854e347fbSGordon Tetlow.El
409d962d52aSRuslan Ermilov.Sh SCRIPTS OF INTEREST
41054e347fbSGordon TetlowWhen an automatic reboot is in progress,
41154e347fbSGordon Tetlow.Nm
41254e347fbSGordon Tetlowis invoked with the argument
413d962d52aSRuslan Ermilov.Cm autoboot .
41454e347fbSGordon TetlowOne of the scripts run from
415d962d52aSRuslan Ermilov.Pa /etc/rc.d/
41654e347fbSGordon Tetlowis
41754e347fbSGordon Tetlow.Pa /etc/rc.d/fsck .
41854e347fbSGordon TetlowThis script runs
41954e347fbSGordon Tetlow.Xr fsck 8
42054e347fbSGordon Tetlowwith option
42154e347fbSGordon Tetlow.Fl p
42254e347fbSGordon Tetlowand
42354e347fbSGordon Tetlow.Fl F
424d962d52aSRuslan Ermilovto
425d962d52aSRuslan Ermilov.Dq preen
426d962d52aSRuslan Ermilovall the disks of minor inconsistencies resulting
427d962d52aSRuslan Ermilovfrom the last system shutdown.
428d962d52aSRuslan ErmilovIf this fails, then checks/repairs of serious inconsistencies
429d962d52aSRuslan Ermilovcaused by hardware or software failure will be performed
430d962d52aSRuslan Ermilovin the background at the end of the booting process.
431d962d52aSRuslan ErmilovIf
432d962d52aSRuslan Ermilov.Cm autoboot
433d962d52aSRuslan Ermilovis not set, when going from single-user to multi-user mode for example,
434d962d52aSRuslan Ermilovthe script does not do anything.
43591e06c00SBen Smithurst.Pp
43654e347fbSGordon TetlowThe
437d962d52aSRuslan Ermilov.Pa /etc/rc.d/local
43854e347fbSGordon Tetlowscript can execute scripts from multiple
439d962d52aSRuslan Ermilov.Nm rc.d/
44091e06c00SBen Smithurstdirectories.
4419a0e6be2SXin LIThe default location includes
4429a0e6be2SXin LI.Pa /usr/local/etc/rc.d/ ,
44391e06c00SBen Smithurstbut these may be overridden with the
44491e06c00SBen Smithurst.Va local_startup
44591e06c00SBen Smithurst.Xr rc.conf 5
44691e06c00SBen Smithurstvariable.
44791e06c00SBen Smithurst.Pp
4488d74f63dSPhilippe CharnierThe
449d962d52aSRuslan Ermilov.Pa /etc/rc.d/serial
4508d74f63dSPhilippe Charnierscript is used to set any special configurations for serial devices.
451afe61c15SRodney W. Grimes.Pp
4528d74f63dSPhilippe CharnierThe
4538d74f63dSPhilippe Charnier.Nm rc.firewall
4548d74f63dSPhilippe Charnierscript is used to configure rules for the kernel based firewall
4551111b49cSSheldon Hearnservice.
4561111b49cSSheldon HearnIt has several possible options:
457e4f980d3SJordan K. Hubbard.Pp
458d962d52aSRuslan Ermilov.Bl -tag -width ".Ar filename" -compact -offset indent
459d962d52aSRuslan Ermilov.It Cm open
460d962d52aSRuslan Ermilovwill allow anyone in
461d962d52aSRuslan Ermilov.It Cm client
462d962d52aSRuslan Ermilovwill try to protect just this machine
463d962d52aSRuslan Ermilov.It Cm simple
464d962d52aSRuslan Ermilovwill try to protect a whole network
465d962d52aSRuslan Ermilov.It Cm closed
466d962d52aSRuslan Ermilovtotally disables IP services except via
467d962d52aSRuslan Ermilov.Pa lo0
468d962d52aSRuslan Ermilovinterface
469d962d52aSRuslan Ermilov.It Cm UNKNOWN
470d962d52aSRuslan Ermilovdisables the loading of firewall rules
471d962d52aSRuslan Ermilov.It Ar filename
472e4f980d3SJordan K. Hubbardwill load the rules in the given filename (full path required).
473e4f980d3SJordan K. Hubbard.El
474e4f980d3SJordan K. Hubbard.Pp
47554e347fbSGordon TetlowMost daemons, including network related daemons, have their own script in
476d962d52aSRuslan Ermilov.Pa /etc/rc.d/ ,
47754e347fbSGordon Tetlowwhich can be used to start, stop, and check the status of the service.
478e4f980d3SJordan K. Hubbard.Pp
47954e347fbSGordon TetlowAny architecture specific scripts, such as
48054e347fbSGordon Tetlow.Pa /etc/rc.d/apm
48154e347fbSGordon Tetlowfor example, specifically check that they are on that architecture
48254e347fbSGordon Tetlowbefore starting the daemon.
483e4f980d3SJordan K. Hubbard.Pp
48454e347fbSGordon TetlowFollowing tradition, all startup files reside in
485afe61c15SRodney W. Grimes.Pa /etc .
4869cbda590SRuslan Ermilov.Sh FILES
487e9074458SGlen Barber.Bl -tag -compact -width Pa
4889cbda590SRuslan Ermilov.It Pa /etc/rc
4899cbda590SRuslan Ermilov.It Pa /etc/rc.conf
4909cbda590SRuslan Ermilov.It Pa /etc/rc.conf.local
4919cbda590SRuslan Ermilov.It Pa /etc/rc.d/
4929cbda590SRuslan Ermilov.It Pa /etc/rc.firewall
4939cbda590SRuslan Ermilov.It Pa /etc/rc.local
4949cbda590SRuslan Ermilov.It Pa /etc/rc.shutdown
4959cbda590SRuslan Ermilov.It Pa /etc/rc.subr
4969cbda590SRuslan Ermilov.It Pa /var/run/dmesg.boot
497a3f9c9fcSRuslan Ermilov.Xr dmesg 8
4989cbda590SRuslan Ermilovresults soon after the
4999cbda590SRuslan Ermilov.Nm
5009cbda590SRuslan Ermilovprocess begins.
501a3f9c9fcSRuslan ErmilovUseful when
502a3f9c9fcSRuslan Ermilov.Xr dmesg 8
503a3f9c9fcSRuslan Ermilovbuffer in the kernel no longer has this information.
5049cbda590SRuslan Ermilov.El
50591e06c00SBen Smithurst.Sh EXAMPLES
50654e347fbSGordon TetlowThe following is a minimal
507d962d52aSRuslan Ermilov.Nm rc.d/
508d962d52aSRuslan Ermilovstyle script.
509d962d52aSRuslan ErmilovMost scripts require little more than the following.
51054e347fbSGordon Tetlow.Bd -literal -offset indent
51154e347fbSGordon Tetlow#!/bin/sh
51254e347fbSGordon Tetlow#
51354e347fbSGordon Tetlow
51454e347fbSGordon Tetlow# PROVIDE: foo
51554e347fbSGordon Tetlow# REQUIRE: bar_service_required_to_precede_foo
51654e347fbSGordon Tetlow
517d962d52aSRuslan Ermilov\&. /etc/rc.subr
51854e347fbSGordon Tetlow
51954e347fbSGordon Tetlowname="foo"
520c86072f5SDoug Bartonrcvar=foo_enable
52154e347fbSGordon Tetlowcommand="/usr/local/bin/foo"
52254e347fbSGordon Tetlow
52354e347fbSGordon Tetlowload_rc_config $name
52454e347fbSGordon Tetlowrun_rc_command "$1"
52554e347fbSGordon Tetlow.Ed
52654e347fbSGordon Tetlow.Pp
527d962d52aSRuslan ErmilovCertain scripts may want to provide enhanced functionality.
528d962d52aSRuslan ErmilovThe user may access this functionality through additional commands.
529d962d52aSRuslan ErmilovThe script may list and define as many commands at it needs.
53054e347fbSGordon Tetlow.Bd -literal -offset indent
53154e347fbSGordon Tetlow#!/bin/sh
53254e347fbSGordon Tetlow#
53354e347fbSGordon Tetlow
53454e347fbSGordon Tetlow# PROVIDE: foo
53554e347fbSGordon Tetlow# REQUIRE: bar_service_required_to_precede_foo
53654e347fbSGordon Tetlow# BEFORE:  baz_service_requiring_foo_to_precede_it
53754e347fbSGordon Tetlow
538d962d52aSRuslan Ermilov\&. /etc/rc.subr
53954e347fbSGordon Tetlow
54054e347fbSGordon Tetlowname="foo"
541c86072f5SDoug Bartonrcvar=foo_enable
54254e347fbSGordon Tetlowcommand="/usr/local/bin/foo"
54354e347fbSGordon Tetlowextra_commands="nop hello"
54454e347fbSGordon Tetlowhello_cmd="echo Hello World."
54554e347fbSGordon Tetlownop_cmd="do_nop"
54654e347fbSGordon Tetlow
54754e347fbSGordon Tetlowdo_nop()
54854e347fbSGordon Tetlow{
54954e347fbSGordon Tetlow	echo "I do nothing."
55054e347fbSGordon Tetlow}
55154e347fbSGordon Tetlow
55254e347fbSGordon Tetlowload_rc_config $name
55354e347fbSGordon Tetlowrun_rc_command "$1"
55454e347fbSGordon Tetlow.Ed
55554e347fbSGordon Tetlow.Pp
55691e06c00SBen SmithurstAs all processes are killed by
55791e06c00SBen Smithurst.Xr init 8
55891e06c00SBen Smithurstat shutdown, the explicit
55991e06c00SBen Smithurst.Xr kill 1
56091e06c00SBen Smithurstis unnecessary, but is often included.
561afe61c15SRodney W. Grimes.Sh SEE ALSO
56291e06c00SBen Smithurst.Xr kill 1 ,
563e4f980d3SJordan K. Hubbard.Xr rc.conf 5 ,
564afe61c15SRodney W. Grimes.Xr init 8 ,
565b25a469fSEugene Grosbein.Xr rc.resume 8 ,
5661c85060aSRuslan Ermilov.Xr rc.subr 8 ,
567121f7af1SBaptiste Daroussin.Xr rcorder 8 ,
568afe61c15SRodney W. Grimes.Xr reboot 8 ,
569e5accd3cSStefan Eßer.Xr savecore 8 ,
570ce6c81b9SAndriy Gapon.Xr service 8 ,
571e5accd3cSStefan Eßer.Xr sysrc 8
572afe61c15SRodney W. Grimes.Sh HISTORY
573afe61c15SRodney W. GrimesThe
574afe61c15SRodney W. Grimes.Nm
5758d74f63dSPhilippe Charnierutility appeared in
576afe61c15SRodney W. Grimes.Bx 4.0 .
577