xref: /netbsd-src/share/man/man8/rc.8 (revision 8119d49919e6a8ed229171d8d68e2dd7053c8e86)
1*8119d499Ssnj.\" 	$NetBSD: rc.8,v 1.41 2024/12/31 01:53:59 snj Exp $
2b5930afcSjtc.\"
3aa650fa7Slukem.\" Copyright (c) 2000-2017 The NetBSD Foundation, Inc.
4e208665dSlukem.\" All rights reserved.
5e208665dSlukem.\"
6e208665dSlukem.\" This code is derived from software contributed to The NetBSD Foundation
7e208665dSlukem.\" by Luke Mewburn.
861f28255Scgd.\"
961f28255Scgd.\" Redistribution and use in source and binary forms, with or without
1061f28255Scgd.\" modification, are permitted provided that the following conditions
1161f28255Scgd.\" are met:
1261f28255Scgd.\" 1. Redistributions of source code must retain the above copyright
1361f28255Scgd.\"    notice, this list of conditions and the following disclaimer.
1461f28255Scgd.\" 2. Redistributions in binary form must reproduce the above copyright
1561f28255Scgd.\"    notice, this list of conditions and the following disclaimer in the
1661f28255Scgd.\"    documentation and/or other materials provided with the distribution.
1761f28255Scgd.\"
18e208665dSlukem.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19e208665dSlukem.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20e208665dSlukem.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21e208665dSlukem.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22e208665dSlukem.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23e208665dSlukem.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24e208665dSlukem.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25e208665dSlukem.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26e208665dSlukem.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27e208665dSlukem.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28e208665dSlukem.\" POSSIBILITY OF SUCH DAMAGE.
2961f28255Scgd.\"
309077f083Smartin.Dd December 7, 2024
3161f28255Scgd.Dt RC 8
3239b11db8Sgarbled.Os
3361f28255Scgd.Sh NAME
34dfdc326bSlukem.Nm rc ,
3583b0eb8aSjruoho.Nm rc.local ,
36dfdc326bSlukem.Nm rc.shutdown ,
379077f083Smartin.Nm rc.shutdown.final ,
38dfdc326bSlukem.Nm rc.d/
39e208665dSlukem.Nd startup and shutdown scripts
4061f28255Scgd.Sh SYNOPSIS
4161f28255Scgd.Nm rc
4283b0eb8aSjruoho.Nm rc.local
43e208665dSlukem.Nm rc.shutdown
44e208665dSlukem.Nm rc.d/
4561f28255Scgd.Sh DESCRIPTION
46e208665dSlukem.Nm
47e208665dSlukemis the command script which controls the startup of various services,
48e208665dSlukemand is invoked by
49e208665dSlukem.Xr init 8
50e208665dSlukemas part of the process of entering the automatic reboot to multi-user startup,
51e208665dSlukemor after the single user mode shell has exited.
52e208665dSlukemIf
53e208665dSlukem.Xr init 8
54e208665dSlukemis starting the automatic reboot process,
55e208665dSlukem.Nm
56e208665dSlukemis invoked with the argument of
57e208665dSlukem.Sq autoboot .
5861f28255Scgd.Pp
5983b0eb8aSjruoho.Nm rc.local
6083b0eb8aSjruohois a command script to which local boot-time actions can be added.
6183b0eb8aSjruohoIt is (nearly) the last thing invoked by
6283b0eb8aSjruoho.Nm rc
6383b0eb8aSjruohoduring a normal boot.
6483b0eb8aSjruoho.Pp
65e208665dSlukem.Nm rc.shutdown
66e208665dSlukemis the command script which shuts down various services, and is invoked by
67e208665dSlukem.Xr shutdown 8
68e208665dSlukemas part of the process of shutting down the system.
6961f28255Scgd.Pp
70e208665dSlukem.Nm rc.d/
71319f9d99Slukemis the directory which contains various
72319f9d99Slukem.Xr sh 1
73319f9d99Slukemscripts, one for each service,
74e208665dSlukemwhich are called by
75e208665dSlukem.Nm
76e208665dSlukemat startup,
77e208665dSlukem.Nm rc.shutdown
78e208665dSlukemat shutdown,
79e208665dSlukemand as necessary during system operation to stop, start, restart, reload,
800e798bbeSlukemor otherwise control the service.
81e208665dSlukem.Ss Operation of rc
82e208665dSlukem.Bl -enum
83e208665dSlukem.It
84e208665dSlukemSource
85e208665dSlukem.Pa /etc/rc.subr
864e990e2eSlukemto load various
874e990e2eSlukem.Xr rc.subr 8
884e990e2eSlukemshell functions to use.
89e208665dSlukem.It
90e208665dSlukemIf autobooting, set
910e798bbeSlukem.Sy autoboot=yes
920e798bbeSlukemand enable a flag
930e798bbeSlukem.Sy ( rc_fast=yes ) ,
940e798bbeSlukemwhich prevents the
95e208665dSlukem.Nm rc.d
96e208665dSlukemscripts from performing the check for already running processes
97e208665dSlukem(thus speeding up the boot process).
980e798bbeSlukemThis
990e798bbeSlukem.Sy rc_fast=yes
1000e798bbeSlukemspeedup won't occur when
101e208665dSlukem.Nm
102e208665dSlukemis started up after exiting the single-user shell.
103e208665dSlukem.It
104e208665dSlukemInvoke
105e208665dSlukem.Xr rcorder 8
10694f61a8cSlukemto order the files in
107e208665dSlukem.Pa /etc/rc.d/
108fa2f9423Slukemthat do not have a
109fa2f9423Slukem.Dq nostart
110fa2f9423Slukemkeyword (refer to
1112a84f851Swiz.Xr rcorder 8 Ns 's
112fa2f9423Slukem.Fl s
113fa2f9423Slukemflag),
114e208665dSlukemand assigns the result to a variable.
115e208665dSlukem.It
11604d90588SapbCalls each script in turn using
11704d90588Sapb.Fn run_rc_script
11804d90588Sapb(from
1194e990e2eSlukem.Xr rc.subr 8 ) ,
120e208665dSlukemwhich sets
121e208665dSlukem.Dv $1
122e208665dSlukemto
123e208665dSlukem.Sq start ,
12496a9fff1Slukemand sources the script in a sub-shell.
125e208665dSlukemIf the script has a
126e208665dSlukem.Sq .sh
127e208665dSlukemsuffix then it is sourced directly into the current shell.
12889fd5357Sapb.It
12989fd5357SapbThe output from the above steps is sent to a post-processor.
13089fd5357SapbIf
13189fd5357Sapb.Sy rc_silent
13289fd5357Sapbis false, then the post-processor displays the output.
13389fd5357SapbIf
13489fd5357Sapb.Sy rc_silent
13589fd5357Sapbis true, then the post-processor invokes the command specified in
13689fd5357Sapb.Va rc_silent_cmd
13789fd5357Sapbonce for each line, without otherwise displaying the output.
13889fd5357SapbUseful values for
13989fd5357Sapb.Va rc_silent_cmd
14089fd5357Sapbinclude
14189fd5357Sapb.Dq \&:
14289fd5357Sapbto display nothing at all, and
14389fd5357Sapb.Dq twiddle
14489fd5357Sapbto display a spinning symbol on the console.
14589fd5357SapbRegardless of the value of
14689fd5357Sapb.Sy rc_silent ,
14789fd5357Sapbthe post-processor saves the output in
14889fd5357Sapb.Pa /var/run/rc.log .
149e208665dSlukem.El
150e208665dSlukem.Ss Operation of rc.shutdown
151e208665dSlukem.Bl -enum
152e208665dSlukem.It
153e208665dSlukemSource
154e208665dSlukem.Pa /etc/rc.subr
1554e990e2eSlukemto load various
1564e990e2eSlukem.Xr rc.subr 8
1574e990e2eSlukemshell functions to use.
158e208665dSlukem.It
159e208665dSlukemInvoke
160e208665dSlukem.Xr rcorder 8
16194f61a8cSlukemto order the files in
16294f61a8cSlukem.Pa /etc/rc.d/
16394f61a8cSlukemthat have a
16494f61a8cSlukem.Dq shutdown
165dbf15525Slukemkeyword (refer to
1662a84f851Swiz.Xr rcorder 8 Ns 's
167dbf15525Slukem.Fl k
168dbf15525Slukemflag),
169e208665dSlukemreverses that order, and assigns the result to a variable.
170e208665dSlukem.It
17104d90588SapbCalls each script in turn using
17204d90588Sapb.Fn run_rc_script
17304d90588Sapb(from
1744e990e2eSlukem.Xr rc.subr 8 ) ,
175e208665dSlukemwhich sets
176e208665dSlukem.Dv $1
177e208665dSlukemto
178e208665dSlukem.Sq stop ,
17996a9fff1Slukemand sources the script in a sub-shell.
180e208665dSlukemIf the script has a
181e208665dSlukem.Sq .sh
182e208665dSlukemsuffix then it is sourced directly into the current shell.
1839077f083Smartin.It
1849077f083SmartinRuns
1859077f083Smartin.Pa /etc/rc.shutdown.final
1869077f083Smartinif it exists, passing the currently ongoing shutdown action, which
1879077f083Smartinwill be one of:
1889077f083Smartin.Bl -bullet
1899077f083Smartin.It
1909077f083Smartinshutdown
1919077f083Smartinwhen going to single user mode.
1929077f083Smartin.It
1939077f083Smartinhalt
1949077f083Smartinwhen halting the machine (but not powering it down).
1959077f083Smartin.It
1969077f083Smartinreboot
1979077f083Smartinwhen rebooting the machine.
1989077f083Smartin.It
1999077f083Smartinpoweroff
2009077f083Smartinwhen halting the machine and powering it off.
2019077f083Smartin.El
2029077f083Smartin.Pp
203*8119d499SsnjThe script may be used to control additional
2049077f083Smartinactions, e.g. powering off external devices, restarting
2059077f083Smartina UPS (in case main power is restored in the interval betweeen
2069077f083Smartinthe computer powering off and the UPS running out of battery).
207e208665dSlukem.El
208e208665dSlukem.Ss Contents of rc.d/
209e208665dSlukem.Nm rc.d/
210e208665dSlukemis located in
211e208665dSlukem.Pa /etc/rc.d .
212e208665dSlukemThe following file naming conventions are currently used in
213e208665dSlukem.Nm rc.d/ :
2140e798bbeSlukem.Bl -tag -width ALLUPPERCASExx -offset indent
2150e798bbeSlukem.It Pa ALLUPPERCASE
216e208665dSlukemScripts that are
217e208665dSlukem.Sq placeholders
2180e798bbeSlukemto ensure that certain operations are performed before others.
219a41efd22SlukemIn order of startup, these are:
2200e798bbeSlukem.Bl -tag -width NETWORKINGxx
2210e798bbeSlukem.It Pa NETWORKING
222cc3f6237SlukemEnsure basic network services are running, including general
223cc3f6237Slukemnetwork configuration
224cc3f6237Slukem.Pq Pa network
225cc3f6237Slukemand
22617af23f7Smaya.Pa dhcpcd .
2270e798bbeSlukem.It Pa SERVERS
228cc3f6237SlukemEnsure basic services (such as
2298923661dSlukem.Pa NETWORKING ,
230cc3f6237Slukem.Pa ppp ,
231cc3f6237Slukem.Pa syslogd ,
232cc3f6237Slukemand
233cc3f6237Slukem.Pa kdc )
234cc3f6237Slukemexist for services that start early (such as
235cc3f6237Slukem.Pa named ) ,
236cc3f6237Slukembecause they're required by
237cc3f6237Slukem.Pa DAEMON
238cc3f6237Slukembelow.
2390e798bbeSlukem.It Pa DAEMON
240cc3f6237SlukemBefore all general purpose daemons such as
241cc3f6237Slukem.Pa dhcpd ,
242cc3f6237Slukem.Pa lpd ,
243cc3f6237Slukemand
244cc3f6237Slukem.Pa ntpd .
2450e798bbeSlukem.It Pa LOGIN
246cc3f6237SlukemBefore user login services
247cc3f6237Slukem.Pa ( inetd ,
248cc3f6237Slukem.Pa telnetd ,
249cc3f6237Slukem.Pa rshd ,
250cc3f6237Slukem.Pa sshd ,
251cc3f6237Slukemand
252cc3f6237Slukem.Pa xdm ) ,
253cc3f6237Slukemas well as before services which might run commands as users
254cc3f6237Slukem.Pa ( cron ,
255cc3f6237Slukem.Pa postfix ,
256cc3f6237Slukemand
257cc3f6237Slukem.Pa sendmail ) .
258e208665dSlukem.El
25996a9fff1Slukem.It Pa inline.sh
26096a9fff1SlukemScripts that are sourced into the current shell rather than a sub-shell
2610e798bbeSlukemhave a
2620e798bbeSlukem.Sq Pa .sh
2630e798bbeSlukemsuffix.
264e208665dSlukemExtreme care must be taken in using this, as the startup sequence will
26596a9fff1Slukemterminate if the script causes the current shell process to terminate.
266fa2f9423Slukem.Pa /etc/rc.d/bootconf.sh
267fa2f9423Slukemuses this behaviour to allow the user to select a different
268fa2f9423Slukemconfiguration (including
269fa2f9423Slukem.Pa /etc/rc.conf )
270fa2f9423Slukemearly in the boot.
27196a9fff1Slukem.It Pa service
27296a9fff1SlukemScripts that are sourced in a sub-shell.
27331edfc6fSapbThe boot does not stop if such a script terminates with a non-zero status,
27431edfc6fSapbbut a script can stop the boot if necessary by invoking the
27531edfc6fSapb.Fn stop_boot
27631edfc6fSapbfunction (from
27731edfc6fSapb.Xr rc.subr 8 ) .
278e208665dSlukem.El
27961f28255Scgd.Pp
2800e798bbeSlukemEach script should contain
2810e798bbeSlukem.Xr rcorder 8
2820e798bbeSlukemkeywords, especially an appropriate
2830e798bbeSlukem.Dq PROVIDE
2840e798bbeSlukementry.
2850e798bbeSlukem.Pp
286e208665dSlukemThe scripts are expected to support at least the following arguments:
287e208665dSlukem.Bl -tag -width restart -offset indent
2880e798bbeSlukem.It Sy start
289bacbe78fSlukemStart the service.
290bacbe78fSlukemThis should check that the service is to be started as specified by
291e208665dSlukem.Xr rc.conf 5 .
292cc3f6237SlukemAlso checks if the service is already running and refuses to start if
293cc3f6237Slukemit is.
294cc3f6237SlukemThis latter check is not performed by standard
295cc3f6237Slukem.Nx
296cc3f6237Slukemscripts if the system is starting directly to multi-user mode, to
297cc3f6237Slukemspeed up the boot process.
2980e798bbeSlukem.It Sy stop
299bacbe78fSlukemIf the service is to be started as specified by
30041f23e2eSsoren.Xr rc.conf 5 ,
301bacbe78fSlukemstop the service.
302bacbe78fSlukemThis should check that the service is running and complain if it's not.
3030e798bbeSlukem.It Sy restart
3040e798bbeSlukemPerform a
3050e798bbeSlukem.Sy stop
3060e798bbeSlukemthen a
3070e798bbeSlukem.Sy start .
3080e798bbeSlukem.It Sy status
309cc3f6237SlukemIf the script starts a process (rather than performing a one-off
310cc3f6237Slukemoperation), show the status of the process.
311cc3f6237SlukemOtherwise it's not necessary to support this argument.
312bacbe78fSlukemDefaults to displaying the process ID of the program (if running).
3130e798bbeSlukem.It Sy poll
3140e798bbeSlukemIf the script starts a process (rather than performing a one-off
3150e798bbeSlukemoperation), wait for the command to exit.
3160e798bbeSlukemOtherwise it's not necessary to support this argument.
3170e798bbeSlukem.It Sy rcvar
318cc3f6237SlukemDisplay which
3194e990e2eSlukem.Xr rc.conf 5
320cc3f6237Slukemvariables are used to control the startup of the service (if any).
321e208665dSlukem.El
322e208665dSlukem.Pp
323e208665dSlukemOther arguments (such as
324e208665dSlukem.Sq reload ,
325e208665dSlukem.Sq dumpdb ,
326e208665dSlukemetc) can be added if necessary.
327e208665dSlukem.Pp
328f3bab2a8SlukemThe argument may have one of the following prefixes to alter its operation:
329f3bab2a8Slukem.Bl -tag -width "force" -offset indent
330f3bab2a8Slukem.It Sy fast
331f3bab2a8SlukemSkip the check for an existing running process.
332f3bab2a8SlukemSets
333f3bab2a8Slukem.Sy rc_fast=yes .
334f3bab2a8Slukem.It Sy force
335f3bab2a8SlukemSkips the
336f3bab2a8Slukem.Xr rc.conf 5
337f3bab2a8Slukemcheck, ignores a failure result from any of the prerequisite checks,
338f3bab2a8Slukemexecutes the command, and always returns a zero exit status.
339f3bab2a8SlukemSets
340f3bab2a8Slukem.Sy rc_force=yes .
341f3bab2a8Slukem.It Sy one
342f3bab2a8SlukemSkips the
343f3bab2a8Slukem.Xr rc.conf 5
34499fe2c9eSwizcheck, but performs all other prerequisite tests.
345f3bab2a8Slukem.El
346f3bab2a8Slukem.Pp
34704d90588SapbIn order to simplify scripts, the
34804d90588Sapb.Fn run_rc_command
34904d90588Sapbfunction from
3504e990e2eSlukem.Xr rc.subr 8
351e208665dSlukemmay be used.
352e208665dSlukem.Sh FILES
353e208665dSlukem.Bl -tag -width /etc/rc.shutdown -compact
354e208665dSlukem.It Pa /etc/rc
355e208665dSlukemStartup script called by
356e208665dSlukem.Xr init 8 .
357e208665dSlukem.It Pa /etc/rc.d/
358e208665dSlukemDirectory containing control scripts for each service.
35983b0eb8aSjruoho.It Pa /etc/rc.local
36083b0eb8aSjruohoLocal startup script.
361e208665dSlukem.It Pa /etc/rc.shutdown
362e208665dSlukemShutdown script called by
363e208665dSlukem.Xr shutdown 8 .
364e208665dSlukem.It Pa /etc/rc.subr
3654e990e2eSlukemContains
3664e990e2eSlukem.Xr rc.subr 8
3674e990e2eSlukemfunctions used by various scripts.
3684e990e2eSlukem.It Pa /etc/rc.conf
3694e990e2eSlukemSystem startup configuration file.
37089fd5357Sapb.It Pa /var/run/rc.log
37189fd5357SapbLog file created by
37289fd5357Sapb.Nm .
373e208665dSlukem.El
374e208665dSlukem.Sh SEE ALSO
375e208665dSlukem.Xr rc.conf 5 ,
376e208665dSlukem.Xr init 8 ,
377868c9ba1Slukem.Xr rc.subr 8 ,
378e208665dSlukem.Xr rcorder 8 ,
37961f28255Scgd.Xr reboot 8 ,
380f6f00e26Smsaitoh.Xr shutdown 8
3819f6376d7Sjruoho.Rs
3829f6376d7Sjruoho.%A Luke Mewburn
3839f6376d7Sjruoho.%T The Design and Implementation of the NetBSD rc.d system
3849f6376d7Sjruoho.%I USENIX Association
3859f6376d7Sjruoho.%B Proceedings of the FREENIX Track: 2001 USENIX Annual Technical Conference
3869f6376d7Sjruoho.%D June 25-30, 2001
38724e35378Swiz.%U http://www.usenix.org/publications/library/proceedings/usenix01/freenix01/full_papers/mewburn/mewburn.pdf
3889f6376d7Sjruoho.Re
38961f28255Scgd.Sh HISTORY
39061f28255ScgdThe
39161f28255Scgd.Nm
39261f28255Scgdcommand appeared in
39361f28255Scgd.Bx 4.0 .
394e208665dSlukemThe
395e208665dSlukem.Pa /etc/rc.d
396fa2f9423Slukemsupport was implemented in
397fa2f9423Slukem.Nx 1.5
3987dc9239dSgrantby
3997dc9239dSgrant.An Luke Mewburn
4007dc9239dSgrant.Aq lukem@NetBSD.org .
40189fd5357SapbThe post-processor, support for
40289fd5357Sapb.Va rc_silent ,
40389fd5357Sapband saving output to a file, was implemented in
40489fd5357Sapb.Nx 6.0
40589fd5357Sapbby
40689fd5357Sapb.An Alan Barrett .
407