xref: /netbsd-src/share/man/man8/rc.8 (revision 3b01aba77a7a698587faaae455bbfe740923c1f5)
1.\" 	$NetBSD: rc.8,v 1.15 2001/05/04 03:22:23 lukem Exp $
2.\"
3.\" Copyright (c) 2000 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 May 4, 2001
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 scripts, one for each service,
70which are called by
71.Nm
72at startup,
73.Nm rc.shutdown
74at shutdown,
75and as necessary during system operation to stop, start, restart, reload,
76(etc) the service.
77.Ss Operation of rc
78.Bl -enum
79.It
80Source
81.Pa /etc/rc.subr
82to load various shell functions to use.
83.It
84If autobooting, set
85.Dv $autoboot
86to
87.Sq yes ,
88and enable a flag which prevents the
89.Nm rc.d
90scripts from performing the check for already running processes
91(thus speeding up the boot process).
92This speedup won't occur when
93.Nm
94is started up after exiting the single-user shell.
95.It
96Invoke
97.Xr rcorder 8
98to order the files in
99.Pa /etc/rc.d/
100that do not have a
101.Dq nostart
102keyword (refer to
103.Xr rcorder 8 's
104.Fl s
105flag),
106and assigns the result to a variable.
107.It
108Calls each script in turn using run_rc_script() (from
109.Pa /etc/rc.subr ) ,
110which sets
111.Dv $1
112to
113.Sq start ,
114and sources the script in a subshell.
115If the script has a
116.Sq .sh
117suffix then it is sourced directly into the current shell.
118.El
119.Ss Operation of rc.shutdown
120.Bl -enum
121.It
122Source
123.Pa /etc/rc.subr
124to load various shell functions to use.
125.It
126Invoke
127.Xr rcorder 8
128to order the files in
129.Pa /etc/rc.d/
130that have a
131.Dq shutdown
132keyword (refer to
133.Xr rcorder 8 's
134.Fl k
135flag),
136reverses that order, and assigns the result to a variable.
137.It
138Calls each script in turn using run_rc_script() (from
139.Pa /etc/rc.subr ) ,
140which sets
141.Dv $1
142to
143.Sq stop ,
144and sources the script in a subshell.
145If the script has a
146.Sq .sh
147suffix then it is sourced directly into the current shell.
148.El
149.Ss Contents of rc.d/
150.Pp
151.Nm rc.d/
152is located in
153.Pa /etc/rc.d .
154The following file naming conventions are currently used in
155.Nm rc.d/ :
156.Bl -tag -width ALLUPPERCASE -offset indent
157.It ALLUPPERCASE
158Scripts that are
159.Sq placeholders
160to ensure that certain operations are done before others.
161In order of startup, these are:
162.Bl -tag -width SERVERS
163.It NETWORK
164Ensure basic network services are running, including general
165network configuration
166.Pq Pa network
167and
168.Pa dhclient .
169.It SERVERS
170Ensure basic services (such as
171.Pa NETWORK ,
172.Pa ppp ,
173.Pa syslogd ,
174and
175.Pa kdc )
176exist for services that start early (such as
177.Pa named ) ,
178because they're required by
179.Pa DAEMON
180below.
181.It DAEMON
182Before all general purpose daemons such as
183.Pa dhcpd ,
184.Pa lpd ,
185and
186.Pa ntpd .
187.It LOGIN
188Before user login services
189.Pa ( inetd ,
190.Pa telnetd ,
191.Pa rshd ,
192.Pa sshd ,
193and
194.Pa xdm ) ,
195as well as before services which might run commands as users
196.Pa ( cron ,
197.Pa postfix ,
198and
199.Pa sendmail ) .
200.El
201.It foo.sh
202Scripts that are to be sourced into the current shell rather than a subshell.
203Extreme care must be taken in using this, as the startup sequence will
204terminate if the script does.
205.Pa /etc/rc.d/bootconf.sh
206uses this behaviour to allow the user to select a different
207configuration (including
208.Pa /etc/rc.conf )
209early in the boot.
210.It bar
211Scripts that are sourced in a subshell.
212These can stop the boot if necessary with the following shell
213commands:
214.Bd -literal -offset
215	if [ "$autoboot" = yes ]; then
216		kill -TERM $$
217	fi
218	exit 1
219.Ed
220.Pp
221Note that this should be used sparingly!
222.El
223.Pp
224The scripts are expected to support at least the following arguments:
225.Bl -tag -width restart -offset indent
226.It start
227Start the service.
228This should check that the service is to be started as specified by
229.Xr rc.conf 5 .
230Also checks if the service is already running and refuses to start if
231it is.
232This latter check is not performed by standard
233.Nx
234scripts if the system is starting directly to multi-user mode, to
235speed up the boot process.
236If
237.Sq forcestart
238is given, ignore the rc.conf check and start anyway.
239.It stop
240If the service is to be started as specified by
241.Xr rc.conf 5 ,
242stop the service.
243This should check that the service is running and complain if it's not.
244If
245.Sq forcestop
246is given, ignore the rc.conf check and attempt to stop.
247.It restart
248Effectively perform a stop then a start.
249.It status
250If the script starts a process (rather than performing a one-off
251operation), show the status of the process.
252Otherwise it's not necessary to support this argument.
253Defaults to displaying the process ID of the program (if running).
254.It rcvar
255Display which
256.Pa /etc/rc.conf
257variables are used to control the startup of the service (if any).
258.El
259.Pp
260Other arguments (such as
261.Sq reload ,
262.Sq dumpdb ,
263etc) can be added if necessary.
264.Pp
265In order to simplify scripts, the run_rc_command() function from
266.Pa /etc/rc.subr
267may be used.
268.Sh FILES
269.Bl -tag -width /etc/rc.shutdown -compact
270.It Pa /etc/rc
271Startup script called by
272.Xr init 8 .
273.It Pa /etc/rc.d/
274Directory containing control scripts for each service.
275.It Pa /etc/rc.shutdown
276Shutdown script called by
277.Xr shutdown 8 .
278.It Pa /etc/rc.subr
279Contains functions used by various scripts.
280.El
281.Sh SEE ALSO
282.Xr rc.conf 5 ,
283.Xr init 8 ,
284.Xr rcorder 8 ,
285.Xr reboot 8 ,
286.Xr shutdown 8
287.Sh HISTORY
288The
289.Nm
290command appeared in
291.Bx 4.0 .
292The
293.Pa /etc/rc.d
294support was implemented in
295.Nx 1.5
296by Luke Mewburn <lukem@netbsd.org>.
297