1.\" $NetBSD: rc.8,v 1.28 2004/01/06 14:46:11 wiz 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 January 6, 2004 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 run_rc_script() (from 115.Xr rc.subr 8 ) , 116which sets 117.Dv $1 118to 119.Sq start , 120and sources the script in a subshell. 121If the script has a 122.Sq .sh 123suffix then it is sourced directly into the current shell. 124.El 125.Ss Operation of rc.shutdown 126.Bl -enum 127.It 128Source 129.Pa /etc/rc.subr 130to load various 131.Xr rc.subr 8 132shell functions to use. 133.It 134Invoke 135.Xr rcorder 8 136to order the files in 137.Pa /etc/rc.d/ 138that have a 139.Dq shutdown 140keyword (refer to 141.Xr rcorder 8 Ns 's 142.Fl k 143flag), 144reverses that order, and assigns the result to a variable. 145.It 146Calls each script in turn using run_rc_script() (from 147.Xr rc.subr 8 ) , 148which sets 149.Dv $1 150to 151.Sq stop , 152and sources the script in a subshell. 153If the script has a 154.Sq .sh 155suffix then it is sourced directly into the current shell. 156.El 157.Ss Contents of rc.d/ 158.Nm rc.d/ 159is located in 160.Pa /etc/rc.d . 161The following file naming conventions are currently used in 162.Nm rc.d/ : 163.Bl -tag -width ALLUPPERCASExx -offset indent 164.It Pa ALLUPPERCASE 165Scripts that are 166.Sq placeholders 167to ensure that certain operations are performed before others. 168In order of startup, these are: 169.Bl -tag -width NETWORKINGxx 170.It Pa NETWORKING 171Ensure basic network services are running, including general 172network configuration 173.Pq Pa network 174and 175.Pa dhclient . 176.It Pa SERVERS 177Ensure basic services (such as 178.Pa NETWORKING , 179.Pa ppp , 180.Pa syslogd , 181and 182.Pa kdc ) 183exist for services that start early (such as 184.Pa named ) , 185because they're required by 186.Pa DAEMON 187below. 188.It Pa DAEMON 189Before all general purpose daemons such as 190.Pa dhcpd , 191.Pa lpd , 192and 193.Pa ntpd . 194.It Pa LOGIN 195Before user login services 196.Pa ( inetd , 197.Pa telnetd , 198.Pa rshd , 199.Pa sshd , 200and 201.Pa xdm ) , 202as well as before services which might run commands as users 203.Pa ( cron , 204.Pa postfix , 205and 206.Pa sendmail ) . 207.El 208.It Pa foo.sh 209Scripts that are to be sourced into the current shell rather than a subshell 210have a 211.Sq Pa .sh 212suffix. 213Extreme care must be taken in using this, as the startup sequence will 214terminate if the script does. 215.Pa /etc/rc.d/bootconf.sh 216uses this behaviour to allow the user to select a different 217configuration (including 218.Pa /etc/rc.conf ) 219early in the boot. 220.It Pa bar 221Scripts that are sourced in a subshell. 222These can stop the boot if necessary with the following shell 223commands: 224.Bd -literal -offset 225 if [ "$autoboot" = yes ]; then 226 kill -TERM $$ 227 fi 228 exit 1 229.Ed 230.Pp 231Note that this should be used extremely sparingly! 232.El 233.Pp 234Each script should contain 235.Xr rcorder 8 236keywords, especially an appropriate 237.Dq PROVIDE 238entry. 239.Pp 240The scripts are expected to support at least the following arguments: 241.Bl -tag -width restart -offset indent 242.It Sy start 243Start the service. 244This should check that the service is to be started as specified by 245.Xr rc.conf 5 . 246Also checks if the service is already running and refuses to start if 247it is. 248This latter check is not performed by standard 249.Nx 250scripts if the system is starting directly to multi-user mode, to 251speed up the boot process. 252.It Sy stop 253If the service is to be started as specified by 254.Xr rc.conf 5 , 255stop the service. 256This should check that the service is running and complain if it's not. 257.It Sy restart 258Perform a 259.Sy stop 260then a 261.Sy start . 262.It Sy status 263If the script starts a process (rather than performing a one-off 264operation), show the status of the process. 265Otherwise it's not necessary to support this argument. 266Defaults to displaying the process ID of the program (if running). 267.It Sy poll 268If the script starts a process (rather than performing a one-off 269operation), wait for the command to exit. 270Otherwise it's not necessary to support this argument. 271.It Sy rcvar 272Display which 273.Xr rc.conf 5 274variables are used to control the startup of the service (if any). 275.El 276.Pp 277Other arguments (such as 278.Sq reload , 279.Sq dumpdb , 280etc) can be added if necessary. 281.Pp 282The argument may have one of the following prefixes to alter its operation: 283.Bl -tag -width "force" -offset indent 284.It Sy fast 285Skip the check for an existing running process. 286Sets 287.Sy rc_fast=yes . 288.It Sy force 289Skips the 290.Xr rc.conf 5 291check, ignores a failure result from any of the prerequisite checks, 292executes the command, and always returns a zero exit status. 293Sets 294.Sy rc_force=yes . 295.It Sy one 296Skips the 297.Xr rc.conf 5 298check, but performs all other prerequisite tests. 299.El 300.Pp 301In order to simplify scripts, the run_rc_command() function from 302.Xr rc.subr 8 303may be used. 304.Sh FILES 305.Bl -tag -width /etc/rc.shutdown -compact 306.It Pa /etc/rc 307Startup script called by 308.Xr init 8 . 309.It Pa /etc/rc.d/ 310Directory containing control scripts for each service. 311.It Pa /etc/rc.shutdown 312Shutdown script called by 313.Xr shutdown 8 . 314.It Pa /etc/rc.subr 315Contains 316.Xr rc.subr 8 317functions used by various scripts. 318.It Pa /etc/rc.conf 319System startup configuration file. 320.El 321.Sh SEE ALSO 322.Xr rc.conf 5 , 323.Xr init 8 , 324.Xr rc.subr 8 , 325.Xr rcorder 8 , 326.Xr reboot 8 , 327.Xr shutdown 8 328.Sh HISTORY 329The 330.Nm 331command appeared in 332.Bx 4.0 . 333The 334.Pa /etc/rc.d 335support was implemented in 336.Nx 1.5 337by 338.An Luke Mewburn 339.Aq lukem@NetBSD.org . 340