xref: /netbsd-src/share/man/man8/rc.8 (revision 4472dbe5e3bd91ef2540bada7a7ca7384627ff9b)
1.\" 	$NetBSD: rc.8,v 1.8 2000/04/29 00:38:43 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 April 28, 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 contents of
99.Pa /etc/rc.d/
100and assigns the result to a variable.
101.It
102Calls each script in turn using run_rc_script() (from
103.Pa /etc/rc.subr ) ,
104which sets
105.Dv $1
106to
107.Sq start ,
108and sources the script in a subshell.
109If the script has a
110.Sq .sh
111suffix then it is sourced directly into the current shell.
112.El
113.Ss Operation of rc.shutdown
114.Bl -enum
115.It
116Source
117.Pa /etc/rc.subr
118to load various shell functions to use.
119.It
120Invoke
121.Xr rcorder 8
122to order the contents of
123.Pa /etc/rc.d/ ,
124reverses that order, and assigns the result to a variable.
125.It
126Calls each script in turn using run_rc_script() (from
127.Pa /etc/rc.subr ) ,
128which sets
129.Dv $1
130to
131.Sq stop ,
132and sources the script in a subshell.
133If the script has a
134.Sq .sh
135suffix then it is sourced directly into the current shell.
136.El
137.Ss Contents of rc.d/
138.Pp
139.Nm rc.d/
140is located in
141.Pa /etc/rc.d .
142The following file naming conventions are currently used in
143.Nm rc.d/ :
144.Bl -tag -width ALLUPPERCASE -offset indent
145.It ALLUPPERCASE
146Scripts that are
147.Sq placeholders
148to ensure that certain operations are done before others, such as:
149.Bl -tag -width SERVERS
150.It DAEMON
151before all daemons
152.It LOGIN
153before user login processes
154.It SERVERS
155ensure basic services exist for services that start early.
156.El
157.It foo.sh
158Scripts that are to be sourced into the current shell rather than a subshell.
159Extreme care must be taken in using this, as the startup sequence will
160terminate if the script does.
161.Pa rc.d/fsck.sh
162uses this behaviour to terminate the boot in case of a failed disk check.
163.It foo
164Scripts that are sourced in a subshell.
165.El
166.Pp
167The scripts are expected to support at least the following arguments:
168.Bl -tag -width restart -offset indent
169.It start
170Start the program.
171This should check that the program is to be started as specified by
172.Xr rc.conf 5 .
173If
174.Sq forcestart
175is given, ignore the rc.conf check and start anyway.
176.It stop
177If the program is to be started as specified by
178.Xr rc.conf 5 ,
179stop the program.
180This should check that the program is running and complain if it's not.
181If
182.Sq forcestop
183is given, ignore the rc.conf check and attempt to stop.
184.It restart
185Effectively perform a stop then a start.
186.It status
187Show the status of the program.
188Defaults to displaying the process ID of the process (if running).
189.El
190.Pp
191Other arguments (such as
192.Sq reload ,
193.Sq dumpdb ,
194etc) can be added if necessary.
195.Pp
196In order to simplify scripts, the run_rc_command() function from
197.Pa /etc/rc.subr
198may be used.
199.Sh FILES
200.Bl -tag -width /etc/rc.shutdown -compact
201.It Pa /etc/rc
202Startup script called by
203.Xr init 8 .
204.It Pa /etc/rc.d/
205Directory containing control scripts for each service.
206.It Pa /etc/rc.shutdown
207Shutdown script called by
208.Xr shutdown 8 .
209.It Pa /etc/rc.subr
210Contains functions used by various scripts.
211.El
212.Sh SEE ALSO
213.Xr rc.conf 5 ,
214.Xr init 8 ,
215.Xr rcorder 8 ,
216.Xr reboot 8 ,
217.Xr shutdown 8 .
218.Sh HISTORY
219The
220.Nm
221command appeared in
222.Bx 4.0 .
223The
224.Pa /etc/rc.d
225support appeared in
226.Nx 1.5 .
227