xref: /freebsd/share/man/man8/rc.8 (revision 9dc67a70650b99872316d7ff95ef45ea4c5b455a)
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.\"
31*9dc67a70SMateusz Piotrowski.Dd September 20, 2024
32afe61c15SRodney W. Grimes.Dt RC 8
333d45e180SRuslan Ermilov.Os
34afe61c15SRodney W. Grimes.Sh NAME
35afe61c15SRodney W. Grimes.Nm rc
36d962d52aSRuslan Ermilov.Nd command scripts for auto-reboot and daemon startup
37afe61c15SRodney W. Grimes.Sh SYNOPSIS
384b66483fSRuslan Ermilov.Nm
39e4f980d3SJordan K. Hubbard.Nm rc.conf
40e4f980d3SJordan K. Hubbard.Nm rc.conf.local
41d962d52aSRuslan Ermilov.Nm rc.d/
42e4f980d3SJordan K. Hubbard.Nm rc.firewall
43afe61c15SRodney W. Grimes.Nm rc.local
44b25a469fSEugene Grosbein.Nm rc.resume
45e4f980d3SJordan K. Hubbard.Nm rc.shutdown
4654e347fbSGordon Tetlow.Nm rc.subr
47afe61c15SRodney W. Grimes.Sh DESCRIPTION
488d74f63dSPhilippe CharnierThe
498d74f63dSPhilippe Charnier.Nm
5054e347fbSGordon Tetlowutility is the command script which controls the automatic boot process
5154e347fbSGordon Tetlowafter being called by
5254e347fbSGordon Tetlow.Xr init 8 .
5354e347fbSGordon TetlowThe
54afe61c15SRodney W. Grimes.Nm rc.local
5554e347fbSGordon Tetlowscript contains commands which are pertinent only
56d962d52aSRuslan Ermilovto a specific site.
57d962d52aSRuslan ErmilovTypically, the
58d962d52aSRuslan Ermilov.Pa /usr/local/etc/rc.d/
5954e347fbSGordon Tetlowmechanism is used instead of
6054e347fbSGordon Tetlow.Nm rc.local
6154e347fbSGordon Tetlowthese days but if
6254e347fbSGordon Tetlowyou want to use
63d962d52aSRuslan Ermilov.Nm rc.local ,
64d962d52aSRuslan Ermilovit is still supported.
65d962d52aSRuslan ErmilovIn this case, it should source
66d962d52aSRuslan Ermilov.Pa /etc/rc.conf
6754e347fbSGordon Tetlowand contain additional custom startup code for your system.
6854e347fbSGordon TetlowThe best way to handle
69d962d52aSRuslan Ermilov.Nm rc.local ,
7054e347fbSGordon Tetlowhowever, is to separate it out into
71d962d52aSRuslan Ermilov.Nm rc.d/
72d962d52aSRuslan Ermilovstyle scripts and place them under
73d962d52aSRuslan Ermilov.Pa /usr/local/etc/rc.d/ .
748d74f63dSPhilippe CharnierThe
758d74f63dSPhilippe Charnier.Nm rc.conf
768d74f63dSPhilippe Charnierfile contains the global system configuration information referenced
7754e347fbSGordon Tetlowby the startup scripts, while
78e4f980d3SJordan K. Hubbard.Nm rc.conf.local
796575e6daSRuslan Ermilovcontains the local system configuration.
806575e6daSRuslan ErmilovSee
8154e347fbSGordon Tetlow.Xr rc.conf 5
8254e347fbSGordon Tetlowfor more information.
83e4f980d3SJordan K. Hubbard.Pp
8491e06c00SBen SmithurstThe
85d962d52aSRuslan Ermilov.Nm rc.d/
8691e06c00SBen Smithurstdirectories contain scripts which will be automatically
8791e06c00SBen Smithurstexecuted at boot time and shutdown time.
8809fdf1f8SStefan Eßer.Pp
89ce6c81b9SAndriy GaponThe
90ce6c81b9SAndriy Gapon.Xr service 8
9109b238e7SAndriy Gaponcommand provides a convenient interface to manage rc.d services.
92ce6c81b9SAndriy Gapon.Pp
93ce6c81b9SAndriy GaponThe
94ce6c81b9SAndriy Gapon.Xr sysrc 8
95ce6c81b9SAndriy Gaponcommand provides a scripting interface to modify system config files.
96d962d52aSRuslan Ermilov.Ss Operation of Nm
9754e347fbSGordon Tetlow.Bl -enum
9854e347fbSGordon Tetlow.It
9954e347fbSGordon TetlowIf autobooting, set
100d962d52aSRuslan Ermilov.Va autoboot Ns = Ns Li yes
10154e347fbSGordon Tetlowand enable a flag
102d962d52aSRuslan Ermilov.Pq Va rc_fast Ns = Ns Li yes ,
10354e347fbSGordon Tetlowwhich prevents the
104d962d52aSRuslan Ermilov.Nm rc.d/
10554e347fbSGordon Tetlowscripts from performing the check for already running processes
10654e347fbSGordon Tetlow(thus speeding up the boot process).
10754e347fbSGordon TetlowThis
108d962d52aSRuslan Ermilov.Va rc_fast Ns = Ns Li yes
109d962d52aSRuslan Ermilovspeedup will not occur when
11054e347fbSGordon Tetlow.Nm
11154e347fbSGordon Tetlowis started up after exiting the single-user shell.
11254e347fbSGordon Tetlow.It
1139eb99781SDoug BartonDetermine whether the system is booting diskless,
1149eb99781SDoug Bartonand if so run the
1159eb99781SDoug Barton.Pa /etc/rc.initdiskless
1169eb99781SDoug Bartonscript.
1179eb99781SDoug Barton.It
1189eb99781SDoug BartonSource
1199eb99781SDoug Barton.Pa /etc/rc.subr
1209eb99781SDoug Bartonto load various
1219eb99781SDoug Barton.Xr rc.subr 8
1229eb99781SDoug Bartonshell functions to use.
1239eb99781SDoug Barton.It
1240981275cSMina GalićLoad the configuration files (see below for reloading).
1259eb99781SDoug Barton.It
1260981275cSMina GalićDetermine if booting in a jail, and add
12781ae4b8dSRuslan Ermilov.Dq Li nojail
1286a774190SJamie Gritton(no jails allowed) or
1296a774190SJamie Gritton.Dq Li nojailvnet
1306a774190SJamie Gritton(only allow vnet-enabled jails) to the list of KEYWORDS to skip in
1319eb99781SDoug Barton.Xr rcorder 8 .
1329eb99781SDoug Barton.It
133cabad264SColin PercivalIf the file
134cabad264SColin Percival.Va ${firstboot_sentinel}
135cabad264SColin Percivaldoes not exist, add
136cabad264SColin Percival.Dq Li firstboot
137cabad264SColin Percivalto the list of KEYWORDS to skip in
138cabad264SColin Percival.Xr rcorder 8 .
139cabad264SColin Percival.It
14054e347fbSGordon TetlowInvoke
14154e347fbSGordon Tetlow.Xr rcorder 8
14254e347fbSGordon Tetlowto order the files in
14354e347fbSGordon Tetlow.Pa /etc/rc.d/
14454e347fbSGordon Tetlowthat do not have a
145d962d52aSRuslan Ermilov.Dq Li nostart
1469eb99781SDoug BartonKEYWORD (refer to
147d962d52aSRuslan Ermilov.Xr rcorder 8 Ns 's
14854e347fbSGordon Tetlow.Fl s
1499eb99781SDoug Bartonflag).
15054e347fbSGordon Tetlow.It
151aa3b7a2fSSimon J. GerratyCall
152aa3b7a2fSSimon J. Gerraty.Fn run_rc_scripts
153aa3b7a2fSSimon J. Gerratywith the list of scripts to be run.
154aa3b7a2fSSimon J. Gerraty.Pp
155aa3b7a2fSSimon J. GerratyFor each script that will call
156d962d52aSRuslan Ermilov.Fn run_rc_script
157aa3b7a2fSSimon J. Gerraty(both functions are 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.
178aa3b7a2fSSimon J. GerratyCall
179aa3b7a2fSSimon J. Gerraty.Fn run_rc_scripts
180aa3b7a2fSSimon J. Gerratyagain with the new list of scripts.
181aa3b7a2fSSimon J. GerratyIt will skip any that have already been run and
182aa3b7a2fSSimon J. Gerratyexecute the rest as described above.
183cabad264SColin Percival.It
184cabad264SColin PercivalIf the file
185cabad264SColin Percival.Va ${firstboot_sentinel}
186cabad264SColin Percivalexists, delete it.
187cabad264SColin PercivalIf the file
188cabad264SColin Percival.Va ${firstboot_sentinel}-reboot
189cabad264SColin Percivalalso exists (because it was created by a script), then delete it and reboot.
19054e347fbSGordon Tetlow.El
191d962d52aSRuslan Ermilov.Ss Operation of Nm rc.shutdown
19254e347fbSGordon Tetlow.Bl -enum
19354e347fbSGordon Tetlow.It
1945fda0d60SAndriy GaponSet
1955fda0d60SAndriy Gapon.Va rc_shutdown
1965fda0d60SAndriy Gaponto the value of the first argument passed to
1975fda0d60SAndriy Gapon.Nm rc.shutdown
1985fda0d60SAndriy Gaponor to
1995fda0d60SAndriy Gapon.Dq Li unspecified
2005fda0d60SAndriy Gaponif no argument was passed.
2015fda0d60SAndriy Gapon.It
20254e347fbSGordon TetlowSource
20354e347fbSGordon Tetlow.Pa /etc/rc.subr
20454e347fbSGordon Tetlowto load various
20554e347fbSGordon Tetlow.Xr rc.subr 8
20654e347fbSGordon Tetlowshell functions to use.
20754e347fbSGordon Tetlow.It
2089eb99781SDoug BartonLoad the configuration files.
2099eb99781SDoug Barton.It
21054e347fbSGordon TetlowInvoke
21154e347fbSGordon Tetlow.Xr rcorder 8
21254e347fbSGordon Tetlowto order the files in
21354e347fbSGordon Tetlow.Pa /etc/rc.d/
2149eb99781SDoug Bartonand the
2159eb99781SDoug Barton.Va $local_startup
2169eb99781SDoug Bartondirectories
21754e347fbSGordon Tetlowthat have a
218d962d52aSRuslan Ermilov.Dq Li shutdown
2199eb99781SDoug BartonKEYWORD (refer to
220d962d52aSRuslan Ermilov.Xr rcorder 8 Ns 's
22154e347fbSGordon Tetlow.Fl k
22254e347fbSGordon Tetlowflag),
223d962d52aSRuslan Ermilovreverse that order, and assign the result to a variable.
22454e347fbSGordon Tetlow.It
225d962d52aSRuslan ErmilovCall each script in turn using
226d962d52aSRuslan Ermilov.Fn run_rc_script
227d962d52aSRuslan Ermilov(from
22854e347fbSGordon Tetlow.Xr rc.subr 8 ) ,
22954e347fbSGordon Tetlowwhich sets
230d962d52aSRuslan Ermilov.Va $1
23154e347fbSGordon Tetlowto
232ce6c81b9SAndriy Gapon.Dq Li faststop ,
23354e347fbSGordon Tetlowand sources the script in a subshell.
23454e347fbSGordon Tetlow.El
235d962d52aSRuslan Ermilov.Ss Contents of Nm rc.d/
23654e347fbSGordon Tetlow.Nm rc.d/
23754e347fbSGordon Tetlowis located in
238d962d52aSRuslan Ermilov.Pa /etc/rc.d/ .
23954e347fbSGordon TetlowThe following file naming conventions are currently used in
24054e347fbSGordon Tetlow.Nm rc.d/ :
241d962d52aSRuslan Ermilov.Bl -tag -width ".Pa ALLUPPERCASE" -offset indent
24254e347fbSGordon Tetlow.It Pa ALLUPPERCASE
24354e347fbSGordon TetlowScripts that are
244d962d52aSRuslan Ermilov.Dq placeholders
24554e347fbSGordon Tetlowto ensure that certain operations are performed before others.
24654e347fbSGordon TetlowIn order of startup, these are:
247c2ebbb55SJohn-Mark Gurney.Bl -tag -width ".Pa FILESYSTEMS"
248c2ebbb55SJohn-Mark Gurney.It Pa FILESYSTEMS
249c2ebbb55SJohn-Mark GurneyEnsure that root and other critical file systems are mounted.
250c2ebbb55SJohn-Mark GurneyThis is the default
251c2ebbb55SJohn-Mark Gurney.Va $early_late_divider .
25254e347fbSGordon Tetlow.It Pa NETWORKING
25354e347fbSGordon TetlowEnsure basic network services are running, including general
2549eb99781SDoug Bartonnetwork configuration.
25554e347fbSGordon Tetlow.It Pa SERVERS
2569eb99781SDoug BartonEnsure basic services
25754e347fbSGordon Tetlowexist for services that start early (such as
25854c22eeaSSergey Kandaurov.Pa nisdomain ) ,
259d962d52aSRuslan Ermilovbecause they are required by
26054e347fbSGordon Tetlow.Pa DAEMON
26154e347fbSGordon Tetlowbelow.
26254e347fbSGordon Tetlow.It Pa DAEMON
26354e347fbSGordon TetlowCheck-point before all general purpose daemons such as
26454e347fbSGordon Tetlow.Pa lpd
26554e347fbSGordon Tetlowand
26654e347fbSGordon Tetlow.Pa ntpd .
26754e347fbSGordon Tetlow.It Pa LOGIN
26854e347fbSGordon TetlowCheck-point before user login services
26954e347fbSGordon Tetlow.Pa ( inetd
27054e347fbSGordon Tetlowand
27154e347fbSGordon Tetlow.Pa sshd ) ,
27254e347fbSGordon Tetlowas well as services which might run commands as users
27354e347fbSGordon Tetlow.Pa ( cron
27454e347fbSGordon Tetlowand
27554e347fbSGordon Tetlow.Pa sendmail ) .
27654e347fbSGordon Tetlow.El
27754e347fbSGordon Tetlow.It Pa bar
27854e347fbSGordon TetlowScripts that are sourced in a subshell.
2793d03791bSMike MakonnenThe boot does not stop if such a script terminates with a non-zero status,
2803d03791bSMike Makonnenbut a script can stop the boot if necessary by invoking the
2813d03791bSMike Makonnen.Fn stop_boot
2823d03791bSMike Makonnenfunction (from
2833d03791bSMike Makonnen.Xr rc.subr 8 ) .
28454e347fbSGordon Tetlow.El
28554e347fbSGordon Tetlow.Pp
28654e347fbSGordon TetlowEach script should contain
28754e347fbSGordon Tetlow.Xr rcorder 8
28854e347fbSGordon Tetlowkeywords, especially an appropriate
289d962d52aSRuslan Ermilov.Dq Li PROVIDE
29054e347fbSGordon Tetlowentry, and if necessary
291d962d52aSRuslan Ermilov.Dq Li REQUIRE
29254e347fbSGordon Tetlowand
293d962d52aSRuslan Ermilov.Dq Li BEFORE
294d962d52aSRuslan Ermilovkeywords.
29554e347fbSGordon Tetlow.Pp
29654e347fbSGordon TetlowEach script is expected to support at least the following arguments, which
297d962d52aSRuslan Ermilovare automatically supported if it uses the
298d962d52aSRuslan Ermilov.Fn run_rc_command
299d962d52aSRuslan Ermilovfunction:
300d962d52aSRuslan Ermilov.Bl -tag -width ".Cm restart" -offset indent
301d962d52aSRuslan Ermilov.It Cm start
30254e347fbSGordon TetlowStart the service.
30354e347fbSGordon TetlowThis should check that the service is to be started as specified by
30454e347fbSGordon Tetlow.Xr rc.conf 5 .
30554e347fbSGordon TetlowAlso checks if the service is already running and refuses to start if
30654e347fbSGordon Tetlowit is.
30754e347fbSGordon TetlowThis latter check is not performed by standard
30854e347fbSGordon Tetlow.Fx
30954e347fbSGordon Tetlowscripts if the system is starting directly to multi-user mode, to
31054e347fbSGordon Tetlowspeed up the boot process.
31154e347fbSGordon TetlowIf
312d962d52aSRuslan Ermilov.Cm forcestart
31354e347fbSGordon Tetlowis given, ignore the
31454e347fbSGordon Tetlow.Xr rc.conf 5
31554e347fbSGordon Tetlowcheck and start anyway.
316d962d52aSRuslan Ermilov.It Cm stop
31754e347fbSGordon TetlowIf the service is to be started as specified by
31854e347fbSGordon Tetlow.Xr rc.conf 5 ,
31954e347fbSGordon Tetlowstop the service.
320d962d52aSRuslan ErmilovThis should check that the service is running and complain if it is not.
32154e347fbSGordon TetlowIf
322d962d52aSRuslan Ermilov.Cm forcestop
32354e347fbSGordon Tetlowis given, ignore the
32454e347fbSGordon Tetlow.Xr rc.conf 5
32554e347fbSGordon Tetlowcheck and attempt to stop.
326d962d52aSRuslan Ermilov.It Cm restart
32754e347fbSGordon TetlowPerform a
328d962d52aSRuslan Ermilov.Cm stop
32954e347fbSGordon Tetlowthen a
330d962d52aSRuslan Ermilov.Cm start .
331d962d52aSRuslan Ermilov.It Cm status
33254e347fbSGordon TetlowIf the script starts a process (rather than performing a one-off
33354e347fbSGordon Tetlowoperation), show the status of the process.
334d962d52aSRuslan ErmilovOtherwise it is not necessary to support this argument.
33554e347fbSGordon TetlowDefaults to displaying the process ID of the program (if running).
336da45b4daSDevin Teske.It Cm enable
337da45b4daSDevin TeskeEnable the service in
338da45b4daSDevin Teske.Xr rc.conf 5 .
339da45b4daSDevin Teske.It Cm disable
340da45b4daSDevin TeskeDisable the service in
341da45b4daSDevin Teske.Xr rc.conf 5 .
342da45b4daSDevin Teske.It Cm delete
343da45b4daSDevin TeskeRemove the service from
344da45b4daSDevin Teske.Xr rc.conf 5 .
345da45b4daSDevin TeskeIf
346da45b4daSDevin Teske.Ql Li service_delete_empty
347da45b4daSDevin Teskeis set to
348da45b4daSDevin Teske.Dq Li YES ,
349da45b4daSDevin Teske.Pa /etc/rc.conf.d/$servicename
350da45b4daSDevin Teskewill be deleted if empty after modification.
3511980d11bSLars Engels.It Cm describe
3521980d11bSLars EngelsPrint a short description of what the script does.
3531980d11bSLars Engels.It Cm extracommands
3541980d11bSLars EngelsPrint the script's non-standard commands.
355d962d52aSRuslan Ermilov.It Cm poll
35654e347fbSGordon TetlowIf the script starts a process (rather than performing a one-off
35754e347fbSGordon Tetlowoperation), wait for the command to exit.
358d962d52aSRuslan ErmilovOtherwise it is not necessary to support this argument.
35949cede74SDag-Erling Smørgrav.It Cm enabled
36049cede74SDag-Erling SmørgravReturn 0 if the service is enabled and 1 if it is not.
36149cede74SDag-Erling SmørgravThis command does not print anything.
362d962d52aSRuslan Ermilov.It Cm rcvar
36354e347fbSGordon TetlowDisplay which
36454e347fbSGordon Tetlow.Xr rc.conf 5
36554e347fbSGordon Tetlowvariables are used to control the startup of the service (if any).
36654e347fbSGordon Tetlow.El
36754e347fbSGordon Tetlow.Pp
36854e347fbSGordon TetlowIf a script must implement additional commands it can list them in
36954e347fbSGordon Tetlowthe
370d962d52aSRuslan Ermilov.Va extra_commands
371d962d52aSRuslan Ermilovvariable, and define their actions in a variable constructed from
37254e347fbSGordon Tetlowthe command name (see the
37354e347fbSGordon Tetlow.Sx EXAMPLES
37454e347fbSGordon Tetlowsection).
37554e347fbSGordon Tetlow.Pp
3760981275cSMina GalićThe configuration files are normally read only once at the start of a boot
3770981275cSMina Galićsequence; if a script needs to
3780981275cSMina Galić.Cm enable
3790981275cSMina Galićor
3800981275cSMina Galić.Cm disable
3810981275cSMina Galićany other script that would run later in the sequence, it must send a
3820981275cSMina Galić.Dv SIGALRM
3830981275cSMina Galićto the rc process (identified by
3840981275cSMina Galić.Ev $RC_PID )
3850981275cSMina Galićto have it re-read the files.
3860981275cSMina Galić.Pp
38754e347fbSGordon TetlowThe following key points apply to old-style scripts in
388d962d52aSRuslan Ermilov.Pa /usr/local/etc/rc.d/ :
389d962d52aSRuslan Ermilov.Bl -bullet
39091e06c00SBen Smithurst.It
39191e06c00SBen SmithurstScripts are only executed if their
39291e06c00SBen Smithurst.Xr basename 1
39391e06c00SBen Smithurstmatches the shell globbing pattern
39491e06c00SBen Smithurst.Pa *.sh ,
39591e06c00SBen Smithurstand they are executable.
39691e06c00SBen SmithurstAny other files or directories present within the directory are silently
39791e06c00SBen Smithurstignored.
39891e06c00SBen Smithurst.It
39991e06c00SBen SmithurstWhen a script is executed at boot time, it is passed the string
400d962d52aSRuslan Ermilov.Dq Li start
40191e06c00SBen Smithurstas its first and only argument.
40291e06c00SBen SmithurstAt shutdown time, it is passed the string
403d962d52aSRuslan Ermilov.Dq Li stop
40491e06c00SBen Smithurstas its first and only argument.
40591e06c00SBen SmithurstAll
406d962d52aSRuslan Ermilov.Nm rc.d/
407d4bbfee2SJens Schweikhardtscripts are expected to handle these arguments appropriately.
40891e06c00SBen SmithurstIf no action needs to be taken at a given time
409d962d52aSRuslan Ermilov(either boot time or shutdown time),
41091e06c00SBen Smithurstthe script should exit successfully and without producing an error message.
41191e06c00SBen Smithurst.It
41291e06c00SBen SmithurstThe scripts within each directory are executed in lexicographical order.
41391e06c00SBen SmithurstIf a specific order is required,
41491e06c00SBen Smithurstnumbers may be used as a prefix to the existing filenames,
41591e06c00SBen Smithurstso for example
41691e06c00SBen Smithurst.Pa 100.foo
41791e06c00SBen Smithurstwould be executed before
41891e06c00SBen Smithurst.Pa 200.bar ;
41991e06c00SBen Smithurstwithout the numeric prefixes the opposite would be true.
42054e347fbSGordon Tetlow.It
42191e06c00SBen SmithurstThe output from each script is traditionally a space character,
42291e06c00SBen Smithurstfollowed by the name of the software package being started or shut down,
42391e06c00SBen Smithurst.Em without
424bb66a3e9SMateusz Piotrowskia trailing newline character.
42554e347fbSGordon Tetlow.El
426d962d52aSRuslan Ermilov.Sh SCRIPTS OF INTEREST
42754e347fbSGordon TetlowWhen an automatic reboot is in progress,
42854e347fbSGordon Tetlow.Nm
42954e347fbSGordon Tetlowis invoked with the argument
430d962d52aSRuslan Ermilov.Cm autoboot .
43154e347fbSGordon TetlowOne of the scripts run from
432d962d52aSRuslan Ermilov.Pa /etc/rc.d/
43354e347fbSGordon Tetlowis
43454e347fbSGordon Tetlow.Pa /etc/rc.d/fsck .
43554e347fbSGordon TetlowThis script runs
43654e347fbSGordon Tetlow.Xr fsck 8
43754e347fbSGordon Tetlowwith option
43854e347fbSGordon Tetlow.Fl p
43954e347fbSGordon Tetlowand
44054e347fbSGordon Tetlow.Fl F
441d962d52aSRuslan Ermilovto
442d962d52aSRuslan Ermilov.Dq preen
443d962d52aSRuslan Ermilovall the disks of minor inconsistencies resulting
444d962d52aSRuslan Ermilovfrom the last system shutdown.
445d962d52aSRuslan ErmilovIf this fails, then checks/repairs of serious inconsistencies
446d962d52aSRuslan Ermilovcaused by hardware or software failure will be performed
447d962d52aSRuslan Ermilovin the background at the end of the booting process.
448d962d52aSRuslan ErmilovIf
449d962d52aSRuslan Ermilov.Cm autoboot
450d962d52aSRuslan Ermilovis not set, when going from single-user to multi-user mode for example,
451d962d52aSRuslan Ermilovthe script does not do anything.
45291e06c00SBen Smithurst.Pp
45354e347fbSGordon TetlowThe
454d962d52aSRuslan Ermilov.Pa /etc/rc.d/serial
4558d74f63dSPhilippe Charnierscript is used to set any special configurations for serial devices.
456afe61c15SRodney W. Grimes.Pp
4578d74f63dSPhilippe CharnierThe
4588d74f63dSPhilippe Charnier.Nm rc.firewall
4598d74f63dSPhilippe Charnierscript is used to configure rules for the kernel based firewall
4601111b49cSSheldon Hearnservice.
4611111b49cSSheldon HearnIt has several possible options:
462e4f980d3SJordan K. Hubbard.Pp
463d962d52aSRuslan Ermilov.Bl -tag -width ".Ar filename" -compact -offset indent
464d962d52aSRuslan Ermilov.It Cm open
465d962d52aSRuslan Ermilovwill allow anyone in
466d962d52aSRuslan Ermilov.It Cm client
467d962d52aSRuslan Ermilovwill try to protect just this machine
468d962d52aSRuslan Ermilov.It Cm simple
469d962d52aSRuslan Ermilovwill try to protect a whole network
470d962d52aSRuslan Ermilov.It Cm closed
471d962d52aSRuslan Ermilovtotally disables IP services except via
472d962d52aSRuslan Ermilov.Pa lo0
473d962d52aSRuslan Ermilovinterface
474d962d52aSRuslan Ermilov.It Cm UNKNOWN
475d962d52aSRuslan Ermilovdisables the loading of firewall rules
476d962d52aSRuslan Ermilov.It Ar filename
477e4f980d3SJordan K. Hubbardwill load the rules in the given filename (full path required).
478e4f980d3SJordan K. Hubbard.El
479e4f980d3SJordan K. Hubbard.Pp
48054e347fbSGordon TetlowMost daemons, including network related daemons, have their own script in
481d962d52aSRuslan Ermilov.Pa /etc/rc.d/ ,
48254e347fbSGordon Tetlowwhich can be used to start, stop, and check the status of the service.
483e4f980d3SJordan K. Hubbard.Pp
48454e347fbSGordon TetlowAny architecture specific scripts, such as
48554e347fbSGordon Tetlow.Pa /etc/rc.d/apm
48654e347fbSGordon Tetlowfor example, specifically check that they are on that architecture
48754e347fbSGordon Tetlowbefore starting the daemon.
488e4f980d3SJordan K. Hubbard.Pp
48954e347fbSGordon TetlowFollowing tradition, all startup files reside in
490afe61c15SRodney W. Grimes.Pa /etc .
4919cbda590SRuslan Ermilov.Sh FILES
492e9074458SGlen Barber.Bl -tag -compact -width Pa
4939cbda590SRuslan Ermilov.It Pa /etc/rc
4949cbda590SRuslan Ermilov.It Pa /etc/rc.conf
4959cbda590SRuslan Ermilov.It Pa /etc/rc.conf.local
4969cbda590SRuslan Ermilov.It Pa /etc/rc.d/
4979cbda590SRuslan Ermilov.It Pa /etc/rc.firewall
4989cbda590SRuslan Ermilov.It Pa /etc/rc.local
4999cbda590SRuslan Ermilov.It Pa /etc/rc.shutdown
5009cbda590SRuslan Ermilov.It Pa /etc/rc.subr
5019cbda590SRuslan Ermilov.It Pa /var/run/dmesg.boot
502a3f9c9fcSRuslan Ermilov.Xr dmesg 8
5039cbda590SRuslan Ermilovresults soon after the
5049cbda590SRuslan Ermilov.Nm
5059cbda590SRuslan Ermilovprocess begins.
506a3f9c9fcSRuslan ErmilovUseful when
507a3f9c9fcSRuslan Ermilov.Xr dmesg 8
508a3f9c9fcSRuslan Ermilovbuffer in the kernel no longer has this information.
5099cbda590SRuslan Ermilov.El
51091e06c00SBen Smithurst.Sh EXAMPLES
51154e347fbSGordon TetlowThe following is a minimal
512d962d52aSRuslan Ermilov.Nm rc.d/
513d962d52aSRuslan Ermilovstyle script.
514d962d52aSRuslan ErmilovMost scripts require little more than the following.
51554e347fbSGordon Tetlow.Bd -literal -offset indent
51654e347fbSGordon Tetlow#!/bin/sh
51754e347fbSGordon Tetlow#
51854e347fbSGordon Tetlow
51954e347fbSGordon Tetlow# PROVIDE: foo
52054e347fbSGordon Tetlow# REQUIRE: bar_service_required_to_precede_foo
52154e347fbSGordon Tetlow
522d962d52aSRuslan Ermilov\&. /etc/rc.subr
52354e347fbSGordon Tetlow
52454e347fbSGordon Tetlowname="foo"
525c86072f5SDoug Bartonrcvar=foo_enable
52654e347fbSGordon Tetlowcommand="/usr/local/bin/foo"
52754e347fbSGordon Tetlow
52854e347fbSGordon Tetlowload_rc_config $name
52954e347fbSGordon Tetlowrun_rc_command "$1"
53054e347fbSGordon Tetlow.Ed
53154e347fbSGordon Tetlow.Pp
532d962d52aSRuslan ErmilovCertain scripts may want to provide enhanced functionality.
533d962d52aSRuslan ErmilovThe user may access this functionality through additional commands.
534d962d52aSRuslan ErmilovThe script may list and define as many commands at it needs.
53554e347fbSGordon Tetlow.Bd -literal -offset indent
53654e347fbSGordon Tetlow#!/bin/sh
53754e347fbSGordon Tetlow#
53854e347fbSGordon Tetlow
53954e347fbSGordon Tetlow# PROVIDE: foo
54054e347fbSGordon Tetlow# REQUIRE: bar_service_required_to_precede_foo
54154e347fbSGordon Tetlow# BEFORE:  baz_service_requiring_foo_to_precede_it
54254e347fbSGordon Tetlow
543d962d52aSRuslan Ermilov\&. /etc/rc.subr
54454e347fbSGordon Tetlow
54554e347fbSGordon Tetlowname="foo"
546c86072f5SDoug Bartonrcvar=foo_enable
54754e347fbSGordon Tetlowcommand="/usr/local/bin/foo"
54854e347fbSGordon Tetlowextra_commands="nop hello"
54954e347fbSGordon Tetlowhello_cmd="echo Hello World."
55054e347fbSGordon Tetlownop_cmd="do_nop"
55154e347fbSGordon Tetlow
55254e347fbSGordon Tetlowdo_nop()
55354e347fbSGordon Tetlow{
55454e347fbSGordon Tetlow	echo "I do nothing."
55554e347fbSGordon Tetlow}
55654e347fbSGordon Tetlow
55754e347fbSGordon Tetlowload_rc_config $name
55854e347fbSGordon Tetlowrun_rc_command "$1"
55954e347fbSGordon Tetlow.Ed
56054e347fbSGordon Tetlow.Pp
56191e06c00SBen SmithurstAs all processes are killed by
56291e06c00SBen Smithurst.Xr init 8
56391e06c00SBen Smithurstat shutdown, the explicit
56491e06c00SBen Smithurst.Xr kill 1
56591e06c00SBen Smithurstis unnecessary, but is often included.
566afe61c15SRodney W. Grimes.Sh SEE ALSO
56791e06c00SBen Smithurst.Xr kill 1 ,
568e4f980d3SJordan K. Hubbard.Xr rc.conf 5 ,
569afe61c15SRodney W. Grimes.Xr init 8 ,
570b25a469fSEugene Grosbein.Xr rc.resume 8 ,
5711c85060aSRuslan Ermilov.Xr rc.subr 8 ,
572121f7af1SBaptiste Daroussin.Xr rcorder 8 ,
573afe61c15SRodney W. Grimes.Xr reboot 8 ,
574e5accd3cSStefan Eßer.Xr savecore 8 ,
575ce6c81b9SAndriy Gapon.Xr service 8 ,
576e5accd3cSStefan Eßer.Xr sysrc 8
577604bc078SMateusz Piotrowski.Pp
578604bc078SMateusz Piotrowski.Rs
579b9f44620SGraham Perrin.%T Practical rc.d scripting in BSD
580b9f44620SGraham Perrin.%U <https://docs.freebsd.org/en/articles/rc-scripting/>
581604bc078SMateusz Piotrowski.Re
582afe61c15SRodney W. Grimes.Sh HISTORY
583afe61c15SRodney W. GrimesThe
584afe61c15SRodney W. Grimes.Nm
5858d74f63dSPhilippe Charnierutility appeared in
586afe61c15SRodney W. Grimes.Bx 4.0 .
587