1.\" $NetBSD: rc.8,v 1.31 2008/04/30 13:10:57 martin 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.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28.\" POSSIBILITY OF SUCH DAMAGE. 29.\" 30.Dd April 6, 2007 31.Dt RC 8 32.Os 33.Sh NAME 34.Nm rc , 35.Nm rc.shutdown , 36.Nm rc.d/ 37.Nd startup and shutdown scripts 38.Sh SYNOPSIS 39.Nm rc 40.Nm rc.shutdown 41.Nm rc.d/ 42.Sh DESCRIPTION 43.Nm 44is the command script which controls the startup of various services, 45and is invoked by 46.Xr init 8 47as part of the process of entering the automatic reboot to multi-user startup, 48or after the single user mode shell has exited. 49If 50.Xr init 8 51is starting the automatic reboot process, 52.Nm 53is invoked with the argument of 54.Sq autoboot . 55.Pp 56.Nm rc.shutdown 57is the command script which shuts down various services, and is invoked by 58.Xr shutdown 8 59as part of the process of shutting down the system. 60.Pp 61.Nm rc.d/ 62is the directory which contains various 63.Xr sh 1 64scripts, one for each service, 65which are called by 66.Nm 67at startup, 68.Nm rc.shutdown 69at shutdown, 70and as necessary during system operation to stop, start, restart, reload, 71or otherwise control the service. 72.Ss Operation of rc 73.Bl -enum 74.It 75Source 76.Pa /etc/rc.subr 77to load various 78.Xr rc.subr 8 79shell functions to use. 80.It 81If autobooting, set 82.Sy autoboot=yes 83and enable a flag 84.Sy ( rc_fast=yes ) , 85which prevents the 86.Nm rc.d 87scripts from performing the check for already running processes 88(thus speeding up the boot process). 89This 90.Sy rc_fast=yes 91speedup won't occur when 92.Nm 93is started up after exiting the single-user shell. 94.It 95Invoke 96.Xr rcorder 8 97to order the files in 98.Pa /etc/rc.d/ 99that do not have a 100.Dq nostart 101keyword (refer to 102.Xr rcorder 8 Ns 's 103.Fl s 104flag), 105and assigns the result to a variable. 106.It 107Calls each script in turn using 108.Fn run_rc_script 109(from 110.Xr rc.subr 8 ) , 111which sets 112.Dv $1 113to 114.Sq start , 115and sources the script in a subshell. 116If the script has a 117.Sq .sh 118suffix then it is sourced directly into the current shell. 119.El 120.Ss Operation of rc.shutdown 121.Bl -enum 122.It 123Source 124.Pa /etc/rc.subr 125to load various 126.Xr rc.subr 8 127shell functions to use. 128.It 129Invoke 130.Xr rcorder 8 131to order the files in 132.Pa /etc/rc.d/ 133that have a 134.Dq shutdown 135keyword (refer to 136.Xr rcorder 8 Ns 's 137.Fl k 138flag), 139reverses that order, and assigns the result to a variable. 140.It 141Calls each script in turn using 142.Fn run_rc_script 143(from 144.Xr rc.subr 8 ) , 145which sets 146.Dv $1 147to 148.Sq stop , 149and sources the script in a subshell. 150If the script has a 151.Sq .sh 152suffix then it is sourced directly into the current shell. 153.El 154.Ss Contents of rc.d/ 155.Nm rc.d/ 156is located in 157.Pa /etc/rc.d . 158The following file naming conventions are currently used in 159.Nm rc.d/ : 160.Bl -tag -width ALLUPPERCASExx -offset indent 161.It Pa ALLUPPERCASE 162Scripts that are 163.Sq placeholders 164to ensure that certain operations are performed before others. 165In order of startup, these are: 166.Bl -tag -width NETWORKINGxx 167.It Pa NETWORKING 168Ensure basic network services are running, including general 169network configuration 170.Pq Pa network 171and 172.Pa dhclient . 173.It Pa SERVERS 174Ensure basic services (such as 175.Pa NETWORKING , 176.Pa ppp , 177.Pa syslogd , 178and 179.Pa kdc ) 180exist for services that start early (such as 181.Pa named ) , 182because they're required by 183.Pa DAEMON 184below. 185.It Pa DAEMON 186Before all general purpose daemons such as 187.Pa dhcpd , 188.Pa lpd , 189and 190.Pa ntpd . 191.It Pa LOGIN 192Before user login services 193.Pa ( inetd , 194.Pa telnetd , 195.Pa rshd , 196.Pa sshd , 197and 198.Pa xdm ) , 199as well as before services which might run commands as users 200.Pa ( cron , 201.Pa postfix , 202and 203.Pa sendmail ) . 204.El 205.It Pa foo.sh 206Scripts that are to be sourced into the current shell rather than a subshell 207have a 208.Sq Pa .sh 209suffix. 210Extreme care must be taken in using this, as the startup sequence will 211terminate if the script does. 212.Pa /etc/rc.d/bootconf.sh 213uses this behaviour to allow the user to select a different 214configuration (including 215.Pa /etc/rc.conf ) 216early in the boot. 217.It Pa bar 218Scripts that are sourced in a subshell. 219The boot does not stop if such a script terminates with a non-zero status, 220but a script can stop the boot if necessary by invoking the 221.Fn stop_boot 222function (from 223.Xr rc.subr 8 ) . 224.El 225.Pp 226Each script should contain 227.Xr rcorder 8 228keywords, especially an appropriate 229.Dq PROVIDE 230entry. 231.Pp 232The scripts are expected to support at least the following arguments: 233.Bl -tag -width restart -offset indent 234.It Sy start 235Start the service. 236This should check that the service is to be started as specified by 237.Xr rc.conf 5 . 238Also checks if the service is already running and refuses to start if 239it is. 240This latter check is not performed by standard 241.Nx 242scripts if the system is starting directly to multi-user mode, to 243speed up the boot process. 244.It Sy stop 245If the service is to be started as specified by 246.Xr rc.conf 5 , 247stop the service. 248This should check that the service is running and complain if it's not. 249.It Sy restart 250Perform a 251.Sy stop 252then a 253.Sy start . 254.It Sy status 255If the script starts a process (rather than performing a one-off 256operation), show the status of the process. 257Otherwise it's not necessary to support this argument. 258Defaults to displaying the process ID of the program (if running). 259.It Sy poll 260If the script starts a process (rather than performing a one-off 261operation), wait for the command to exit. 262Otherwise it's not necessary to support this argument. 263.It Sy rcvar 264Display which 265.Xr rc.conf 5 266variables are used to control the startup of the service (if any). 267.El 268.Pp 269Other arguments (such as 270.Sq reload , 271.Sq dumpdb , 272etc) can be added if necessary. 273.Pp 274The argument may have one of the following prefixes to alter its operation: 275.Bl -tag -width "force" -offset indent 276.It Sy fast 277Skip the check for an existing running process. 278Sets 279.Sy rc_fast=yes . 280.It Sy force 281Skips the 282.Xr rc.conf 5 283check, ignores a failure result from any of the prerequisite checks, 284executes the command, and always returns a zero exit status. 285Sets 286.Sy rc_force=yes . 287.It Sy one 288Skips the 289.Xr rc.conf 5 290check, but performs all other prerequisite tests. 291.El 292.Pp 293In order to simplify scripts, the 294.Fn run_rc_command 295function from 296.Xr rc.subr 8 297may be used. 298.Sh FILES 299.Bl -tag -width /etc/rc.shutdown -compact 300.It Pa /etc/rc 301Startup script called by 302.Xr init 8 . 303.It Pa /etc/rc.d/ 304Directory containing control scripts for each service. 305.It Pa /etc/rc.shutdown 306Shutdown script called by 307.Xr shutdown 8 . 308.It Pa /etc/rc.subr 309Contains 310.Xr rc.subr 8 311functions used by various scripts. 312.It Pa /etc/rc.conf 313System startup configuration file. 314.El 315.Sh SEE ALSO 316.Xr rc.conf 5 , 317.Xr init 8 , 318.Xr rc.subr 8 , 319.Xr rcorder 8 , 320.Xr reboot 8 , 321.Xr shutdown 8 322.Sh HISTORY 323The 324.Nm 325command appeared in 326.Bx 4.0 . 327The 328.Pa /etc/rc.d 329support was implemented in 330.Nx 1.5 331by 332.An Luke Mewburn 333.Aq lukem@NetBSD.org . 334