1.\" $NetBSD: rc.8,v 1.24 2002/04/18 11:14:33 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 18, 2002 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 '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 '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. 252If 253.Sq forcestart 254is given, ignore the 255.Xr rc.conf 5 256check and start anyway. 257.It Sy stop 258If the service is to be started as specified by 259.Xr rc.conf 5 , 260stop the service. 261This should check that the service is running and complain if it's not. 262If 263.Sq forcestop 264is given, ignore the 265.Xr rc.conf 5 266check and attempt to stop. 267.It Sy restart 268Perform a 269.Sy stop 270then a 271.Sy start . 272.It Sy status 273If the script starts a process (rather than performing a one-off 274operation), show the status of the process. 275Otherwise it's not necessary to support this argument. 276Defaults to displaying the process ID of the program (if running). 277.It Sy poll 278If the script starts a process (rather than performing a one-off 279operation), wait for the command to exit. 280Otherwise it's not necessary to support this argument. 281.It Sy rcvar 282Display which 283.Xr rc.conf 5 284variables are used to control the startup of the service (if any). 285.El 286.Pp 287Other arguments (such as 288.Sq reload , 289.Sq dumpdb , 290etc) can be added if necessary. 291.Pp 292In order to simplify scripts, the run_rc_command() function from 293.Xr rc.subr 8 294may be used. 295.Sh FILES 296.Bl -tag -width /etc/rc.shutdown -compact 297.It Pa /etc/rc 298Startup script called by 299.Xr init 8 . 300.It Pa /etc/rc.d/ 301Directory containing control scripts for each service. 302.It Pa /etc/rc.shutdown 303Shutdown script called by 304.Xr shutdown 8 . 305.It Pa /etc/rc.subr 306Contains 307.Xr rc.subr 8 308functions used by various scripts. 309.It Pa /etc/rc.conf 310System startup configuration file. 311.El 312.Sh SEE ALSO 313.Xr rc.conf 5 , 314.Xr init 8 , 315.Xr rc.subr 8 , 316.Xr rcorder 8 , 317.Xr reboot 8 , 318.Xr shutdown 8 319.Sh HISTORY 320The 321.Nm 322command appeared in 323.Bx 4.0 . 324The 325.Pa /etc/rc.d 326support was implemented in 327.Nx 1.5 328by Luke Mewburn \*[Lt]lukem@netbsd.org\*[Gt]. 329