1.\" $NetBSD: rc.8,v 1.17 2001/11/25 23:42:22 wiz 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.Nm rc.d/ 151is located in 152.Pa /etc/rc.d . 153The following file naming conventions are currently used in 154.Nm rc.d/ : 155.Bl -tag -width ALLUPPERCASE -offset indent 156.It ALLUPPERCASE 157Scripts that are 158.Sq placeholders 159to ensure that certain operations are done before others. 160In order of startup, these are: 161.Bl -tag -width SERVERS 162.It NETWORK 163Ensure basic network services are running, including general 164network configuration 165.Pq Pa network 166and 167.Pa dhclient . 168.It SERVERS 169Ensure basic services (such as 170.Pa NETWORK , 171.Pa ppp , 172.Pa syslogd , 173and 174.Pa kdc ) 175exist for services that start early (such as 176.Pa named ) , 177because they're required by 178.Pa DAEMON 179below. 180.It DAEMON 181Before all general purpose daemons such as 182.Pa dhcpd , 183.Pa lpd , 184and 185.Pa ntpd . 186.It LOGIN 187Before user login services 188.Pa ( inetd , 189.Pa telnetd , 190.Pa rshd , 191.Pa sshd , 192and 193.Pa xdm ) , 194as well as before services which might run commands as users 195.Pa ( cron , 196.Pa postfix , 197and 198.Pa sendmail ) . 199.El 200.It foo.sh 201Scripts that are to be sourced into the current shell rather than a subshell. 202Extreme care must be taken in using this, as the startup sequence will 203terminate if the script does. 204.Pa /etc/rc.d/bootconf.sh 205uses this behaviour to allow the user to select a different 206configuration (including 207.Pa /etc/rc.conf ) 208early in the boot. 209.It bar 210Scripts that are sourced in a subshell. 211These can stop the boot if necessary with the following shell 212commands: 213.Bd -literal -offset 214 if [ "$autoboot" = yes ]; then 215 kill -TERM $$ 216 fi 217 exit 1 218.Ed 219.Pp 220Note that this should be used sparingly! 221.El 222.Pp 223The scripts are expected to support at least the following arguments: 224.Bl -tag -width restart -offset indent 225.It start 226Start the service. 227This should check that the service is to be started as specified by 228.Xr rc.conf 5 . 229Also checks if the service is already running and refuses to start if 230it is. 231This latter check is not performed by standard 232.Nx 233scripts if the system is starting directly to multi-user mode, to 234speed up the boot process. 235If 236.Sq forcestart 237is given, ignore the rc.conf check and start anyway. 238.It stop 239If the service is to be started as specified by 240.Xr rc.conf 5 , 241stop the service. 242This should check that the service is running and complain if it's not. 243If 244.Sq forcestop 245is given, ignore the rc.conf check and attempt to stop. 246.It restart 247Effectively perform a stop then a start. 248.It status 249If the script starts a process (rather than performing a one-off 250operation), show the status of the process. 251Otherwise it's not necessary to support this argument. 252Defaults to displaying the process ID of the program (if running). 253.It rcvar 254Display which 255.Pa /etc/rc.conf 256variables are used to control the startup of the service (if any). 257.El 258.Pp 259Other arguments (such as 260.Sq reload , 261.Sq dumpdb , 262etc) can be added if necessary. 263.Pp 264In order to simplify scripts, the run_rc_command() function from 265.Pa /etc/rc.subr 266may be used. 267.Sh FILES 268.Bl -tag -width /etc/rc.shutdown -compact 269.It Pa /etc/rc 270Startup script called by 271.Xr init 8 . 272.It Pa /etc/rc.d/ 273Directory containing control scripts for each service. 274.It Pa /etc/rc.shutdown 275Shutdown script called by 276.Xr shutdown 8 . 277.It Pa /etc/rc.subr 278Contains functions used by various scripts. 279.El 280.Sh SEE ALSO 281.Xr rc.conf 5 , 282.Xr init 8 , 283.Xr rcorder 8 , 284.Xr reboot 8 , 285.Xr shutdown 8 286.Sh HISTORY 287The 288.Nm 289command appeared in 290.Bx 4.0 . 291The 292.Pa /etc/rc.d 293support was implemented in 294.Nx 1.5 295by Luke Mewburn <lukem@netbsd.org>. 296