xref: /netbsd-src/share/man/man8/rc.8 (revision 8b0f9554ff8762542c4defc4f70e1eb76fb508fa)
1.\" 	$NetBSD: rc.8,v 1.30 2007/04/06 14:20:17 apb Exp $
2.\"
3.\" Copyright (c) 2000-2004 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Luke Mewburn.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\" 3. All advertising materials mentioning features or use of this software
18.\"    must display the following acknowledgement:
19.\"	This product includes software developed by the NetBSD
20.\"	Foundation, Inc. and its contributors.
21.\" 4. Neither the name of The NetBSD Foundation nor the names of its
22.\"    contributors may be used to endorse or promote products derived
23.\"    from this software without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35.\" POSSIBILITY OF SUCH DAMAGE.
36.\"
37.Dd April 6, 2007
38.Dt RC 8
39.Os
40.Sh NAME
41.Nm rc ,
42.Nm rc.shutdown ,
43.Nm rc.d/
44.Nd startup and shutdown scripts
45.Sh SYNOPSIS
46.Nm rc
47.Nm rc.shutdown
48.Nm rc.d/
49.Sh DESCRIPTION
50.Nm
51is the command script which controls the startup of various services,
52and is invoked by
53.Xr init 8
54as part of the process of entering the automatic reboot to multi-user startup,
55or after the single user mode shell has exited.
56If
57.Xr init 8
58is starting the automatic reboot process,
59.Nm
60is invoked with the argument of
61.Sq autoboot .
62.Pp
63.Nm rc.shutdown
64is the command script which shuts down various services, and is invoked by
65.Xr shutdown 8
66as part of the process of shutting down the system.
67.Pp
68.Nm rc.d/
69is the directory which contains various
70.Xr sh 1
71scripts, one for each service,
72which are called by
73.Nm
74at startup,
75.Nm rc.shutdown
76at shutdown,
77and as necessary during system operation to stop, start, restart, reload,
78or otherwise control the service.
79.Ss Operation of rc
80.Bl -enum
81.It
82Source
83.Pa /etc/rc.subr
84to load various
85.Xr rc.subr 8
86shell functions to use.
87.It
88If autobooting, set
89.Sy autoboot=yes
90and enable a flag
91.Sy ( rc_fast=yes ) ,
92which prevents the
93.Nm rc.d
94scripts from performing the check for already running processes
95(thus speeding up the boot process).
96This
97.Sy rc_fast=yes
98speedup won't occur when
99.Nm
100is started up after exiting the single-user shell.
101.It
102Invoke
103.Xr rcorder 8
104to order the files in
105.Pa /etc/rc.d/
106that do not have a
107.Dq nostart
108keyword (refer to
109.Xr rcorder 8 Ns 's
110.Fl s
111flag),
112and assigns the result to a variable.
113.It
114Calls each script in turn using
115.Fn run_rc_script
116(from
117.Xr rc.subr 8 ) ,
118which sets
119.Dv $1
120to
121.Sq start ,
122and sources the script in a subshell.
123If the script has a
124.Sq .sh
125suffix then it is sourced directly into the current shell.
126.El
127.Ss Operation of rc.shutdown
128.Bl -enum
129.It
130Source
131.Pa /etc/rc.subr
132to load various
133.Xr rc.subr 8
134shell functions to use.
135.It
136Invoke
137.Xr rcorder 8
138to order the files in
139.Pa /etc/rc.d/
140that have a
141.Dq shutdown
142keyword (refer to
143.Xr rcorder 8 Ns 's
144.Fl k
145flag),
146reverses that order, and assigns the result to a variable.
147.It
148Calls each script in turn using
149.Fn run_rc_script
150(from
151.Xr rc.subr 8 ) ,
152which sets
153.Dv $1
154to
155.Sq stop ,
156and sources the script in a subshell.
157If the script has a
158.Sq .sh
159suffix then it is sourced directly into the current shell.
160.El
161.Ss Contents of rc.d/
162.Nm rc.d/
163is located in
164.Pa /etc/rc.d .
165The following file naming conventions are currently used in
166.Nm rc.d/ :
167.Bl -tag -width ALLUPPERCASExx -offset indent
168.It Pa ALLUPPERCASE
169Scripts that are
170.Sq placeholders
171to ensure that certain operations are performed before others.
172In order of startup, these are:
173.Bl -tag -width NETWORKINGxx
174.It Pa NETWORKING
175Ensure basic network services are running, including general
176network configuration
177.Pq Pa network
178and
179.Pa dhclient .
180.It Pa SERVERS
181Ensure basic services (such as
182.Pa NETWORKING ,
183.Pa ppp ,
184.Pa syslogd ,
185and
186.Pa kdc )
187exist for services that start early (such as
188.Pa named ) ,
189because they're required by
190.Pa DAEMON
191below.
192.It Pa DAEMON
193Before all general purpose daemons such as
194.Pa dhcpd ,
195.Pa lpd ,
196and
197.Pa ntpd .
198.It Pa LOGIN
199Before user login services
200.Pa ( inetd ,
201.Pa telnetd ,
202.Pa rshd ,
203.Pa sshd ,
204and
205.Pa xdm ) ,
206as well as before services which might run commands as users
207.Pa ( cron ,
208.Pa postfix ,
209and
210.Pa sendmail ) .
211.El
212.It Pa foo.sh
213Scripts that are to be sourced into the current shell rather than a subshell
214have a
215.Sq Pa .sh
216suffix.
217Extreme care must be taken in using this, as the startup sequence will
218terminate if the script does.
219.Pa /etc/rc.d/bootconf.sh
220uses this behaviour to allow the user to select a different
221configuration (including
222.Pa /etc/rc.conf )
223early in the boot.
224.It Pa bar
225Scripts that are sourced in a subshell.
226The boot does not stop if such a script terminates with a non-zero status,
227but a script can stop the boot if necessary by invoking the
228.Fn stop_boot
229function (from
230.Xr rc.subr 8 ) .
231.El
232.Pp
233Each script should contain
234.Xr rcorder 8
235keywords, especially an appropriate
236.Dq PROVIDE
237entry.
238.Pp
239The scripts are expected to support at least the following arguments:
240.Bl -tag -width restart -offset indent
241.It Sy start
242Start the service.
243This should check that the service is to be started as specified by
244.Xr rc.conf 5 .
245Also checks if the service is already running and refuses to start if
246it is.
247This latter check is not performed by standard
248.Nx
249scripts if the system is starting directly to multi-user mode, to
250speed up the boot process.
251.It Sy stop
252If the service is to be started as specified by
253.Xr rc.conf 5 ,
254stop the service.
255This should check that the service is running and complain if it's not.
256.It Sy restart
257Perform a
258.Sy stop
259then a
260.Sy start .
261.It Sy status
262If the script starts a process (rather than performing a one-off
263operation), show the status of the process.
264Otherwise it's not necessary to support this argument.
265Defaults to displaying the process ID of the program (if running).
266.It Sy poll
267If the script starts a process (rather than performing a one-off
268operation), wait for the command to exit.
269Otherwise it's not necessary to support this argument.
270.It Sy rcvar
271Display which
272.Xr rc.conf 5
273variables are used to control the startup of the service (if any).
274.El
275.Pp
276Other arguments (such as
277.Sq reload ,
278.Sq dumpdb ,
279etc) can be added if necessary.
280.Pp
281The argument may have one of the following prefixes to alter its operation:
282.Bl -tag -width "force" -offset indent
283.It Sy fast
284Skip the check for an existing running process.
285Sets
286.Sy rc_fast=yes .
287.It Sy force
288Skips the
289.Xr rc.conf 5
290check, ignores a failure result from any of the prerequisite checks,
291executes the command, and always returns a zero exit status.
292Sets
293.Sy rc_force=yes .
294.It Sy one
295Skips the
296.Xr rc.conf 5
297check, but performs all other prerequisite tests.
298.El
299.Pp
300In order to simplify scripts, the
301.Fn run_rc_command
302function from
303.Xr rc.subr 8
304may be used.
305.Sh FILES
306.Bl -tag -width /etc/rc.shutdown -compact
307.It Pa /etc/rc
308Startup script called by
309.Xr init 8 .
310.It Pa /etc/rc.d/
311Directory containing control scripts for each service.
312.It Pa /etc/rc.shutdown
313Shutdown script called by
314.Xr shutdown 8 .
315.It Pa /etc/rc.subr
316Contains
317.Xr rc.subr 8
318functions used by various scripts.
319.It Pa /etc/rc.conf
320System startup configuration file.
321.El
322.Sh SEE ALSO
323.Xr rc.conf 5 ,
324.Xr init 8 ,
325.Xr rc.subr 8 ,
326.Xr rcorder 8 ,
327.Xr reboot 8 ,
328.Xr shutdown 8
329.Sh HISTORY
330The
331.Nm
332command appeared in
333.Bx 4.0 .
334The
335.Pa /etc/rc.d
336support was implemented in
337.Nx 1.5
338by
339.An Luke Mewburn
340.Aq lukem@NetBSD.org .
341