xref: /netbsd-src/share/man/man8/rc.8 (revision 5aefcfdc06931dd97e76246d2fe0302f7b3fe094)
1.\" 	$NetBSD: rc.8,v 1.14 2000/12/15 00:57:27 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 December 14, 2000
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
165.It SERVERS
166ensure basic services exist for services that start early
167.It DAEMON
168before all general purpose daemons
169.It LOGIN
170before user login processes
171.El
172.It foo.sh
173Scripts that are to be sourced into the current shell rather than a subshell.
174Extreme care must be taken in using this, as the startup sequence will
175terminate if the script does.
176.Pa /etc/rc.d/bootconf.sh
177uses this behaviour to allow the user to select a different
178configuration (including
179.Pa /etc/rc.conf )
180early in the boot.
181.It bar
182Scripts that are sourced in a subshell.
183These can stop the boot if necessary with the following shell
184commands:
185.Bd -literal -offset
186	if [ "$autoboot" = yes ]; then
187		kill -TERM $$
188	fi
189	exit 1
190.Ed
191.Pp
192Note that this should be used sparingly!
193.El
194.Pp
195The scripts are expected to support at least the following arguments:
196.Bl -tag -width restart -offset indent
197.It start
198Start the service.
199This should check that the service is to be started as specified by
200.Xr rc.conf 5 .
201If
202.Sq forcestart
203is given, ignore the rc.conf check and start anyway.
204.It stop
205If the service is to be started as specified by
206.Xr rc.conf 5 ,
207stop the service.
208This should check that the service is running and complain if it's not.
209If
210.Sq forcestop
211is given, ignore the rc.conf check and attempt to stop.
212.It restart
213Effectively perform a stop then a start.
214.It status
215Show the status of the service.
216Defaults to displaying the process ID of the program (if running).
217.El
218.Pp
219Other arguments (such as
220.Sq reload ,
221.Sq dumpdb ,
222etc) can be added if necessary.
223.Pp
224In order to simplify scripts, the run_rc_command() function from
225.Pa /etc/rc.subr
226may be used.
227.Sh FILES
228.Bl -tag -width /etc/rc.shutdown -compact
229.It Pa /etc/rc
230Startup script called by
231.Xr init 8 .
232.It Pa /etc/rc.d/
233Directory containing control scripts for each service.
234.It Pa /etc/rc.shutdown
235Shutdown script called by
236.Xr shutdown 8 .
237.It Pa /etc/rc.subr
238Contains functions used by various scripts.
239.El
240.Sh SEE ALSO
241.Xr rc.conf 5 ,
242.Xr init 8 ,
243.Xr rcorder 8 ,
244.Xr reboot 8 ,
245.Xr shutdown 8
246.Sh HISTORY
247The
248.Nm
249command appeared in
250.Bx 4.0 .
251The
252.Pa /etc/rc.d
253support was implemented in
254.Nx 1.5
255by Luke Mewburn <lukem@netbsd.org>.
256