2017-10-15 00:21:51 +03:00
|
|
|
.\" $NetBSD: rc.8,v 1.39 2017/10/14 21:21:51 lukem Exp $
|
1994-11-30 22:31:07 +03:00
|
|
|
.\"
|
2017-10-12 02:42:33 +03:00
|
|
|
.\" Copyright (c) 2000-2017 The NetBSD Foundation, Inc.
|
2000-04-28 10:10:54 +04:00
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
.\" by Luke Mewburn.
|
1993-03-21 12:45:37 +03:00
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\"
|
2000-04-28 10:10:54 +04:00
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
.\" POSSIBILITY OF SUCH DAMAGE.
|
1993-03-21 12:45:37 +03:00
|
|
|
.\"
|
2017-10-15 00:21:51 +03:00
|
|
|
.Dd October 15, 2017
|
1993-03-21 12:45:37 +03:00
|
|
|
.Dt RC 8
|
1999-03-17 23:31:19 +03:00
|
|
|
.Os
|
1993-03-21 12:45:37 +03:00
|
|
|
.Sh NAME
|
2000-04-28 10:13:00 +04:00
|
|
|
.Nm rc ,
|
2010-05-14 20:19:58 +04:00
|
|
|
.Nm rc.local ,
|
2000-04-28 10:13:00 +04:00
|
|
|
.Nm rc.shutdown ,
|
|
|
|
.Nm rc.d/
|
2000-04-28 10:10:54 +04:00
|
|
|
.Nd startup and shutdown scripts
|
1993-03-21 12:45:37 +03:00
|
|
|
.Sh SYNOPSIS
|
|
|
|
.Nm rc
|
2010-05-14 20:19:58 +04:00
|
|
|
.Nm rc.local
|
2000-04-28 10:10:54 +04:00
|
|
|
.Nm rc.shutdown
|
|
|
|
.Nm rc.d/
|
1993-03-21 12:45:37 +03:00
|
|
|
.Sh DESCRIPTION
|
2000-04-28 10:10:54 +04:00
|
|
|
.Nm
|
|
|
|
is the command script which controls the startup of various services,
|
|
|
|
and is invoked by
|
|
|
|
.Xr init 8
|
|
|
|
as part of the process of entering the automatic reboot to multi-user startup,
|
|
|
|
or after the single user mode shell has exited.
|
|
|
|
If
|
|
|
|
.Xr init 8
|
|
|
|
is starting the automatic reboot process,
|
|
|
|
.Nm
|
|
|
|
is invoked with the argument of
|
|
|
|
.Sq autoboot .
|
1993-03-21 12:45:37 +03:00
|
|
|
.Pp
|
2010-05-14 20:19:58 +04:00
|
|
|
.Nm rc.local
|
|
|
|
is a command script to which local boot-time actions can be added.
|
|
|
|
It is (nearly) the last thing invoked by
|
|
|
|
.Nm rc
|
|
|
|
during a normal boot.
|
|
|
|
.Pp
|
2000-04-28 10:10:54 +04:00
|
|
|
.Nm rc.shutdown
|
|
|
|
is the command script which shuts down various services, and is invoked by
|
|
|
|
.Xr shutdown 8
|
|
|
|
as part of the process of shutting down the system.
|
1993-03-21 12:45:37 +03:00
|
|
|
.Pp
|
2000-04-28 10:10:54 +04:00
|
|
|
.Nm rc.d/
|
2002-02-25 07:09:15 +03:00
|
|
|
is the directory which contains various
|
2002-02-25 14:21:38 +03:00
|
|
|
.Xr sh 1
|
2002-02-25 07:09:15 +03:00
|
|
|
scripts, one for each service,
|
2000-04-28 10:10:54 +04:00
|
|
|
which are called by
|
|
|
|
.Nm
|
|
|
|
at startup,
|
|
|
|
.Nm rc.shutdown
|
|
|
|
at shutdown,
|
|
|
|
and as necessary during system operation to stop, start, restart, reload,
|
2002-04-18 15:14:33 +04:00
|
|
|
or otherwise control the service.
|
2000-04-28 10:10:54 +04:00
|
|
|
.Ss Operation of rc
|
|
|
|
.Bl -enum
|
|
|
|
.It
|
|
|
|
Source
|
|
|
|
.Pa /etc/rc.subr
|
2002-03-22 07:32:10 +03:00
|
|
|
to load various
|
|
|
|
.Xr rc.subr 8
|
|
|
|
shell functions to use.
|
2000-04-28 10:10:54 +04:00
|
|
|
.It
|
|
|
|
If autobooting, set
|
2002-04-18 15:14:33 +04:00
|
|
|
.Sy autoboot=yes
|
|
|
|
and enable a flag
|
|
|
|
.Sy ( rc_fast=yes ) ,
|
|
|
|
which prevents the
|
2000-04-28 10:10:54 +04:00
|
|
|
.Nm rc.d
|
|
|
|
scripts from performing the check for already running processes
|
|
|
|
(thus speeding up the boot process).
|
2002-04-18 15:14:33 +04:00
|
|
|
This
|
|
|
|
.Sy rc_fast=yes
|
|
|
|
speedup won't occur when
|
2000-04-28 10:10:54 +04:00
|
|
|
.Nm
|
|
|
|
is started up after exiting the single-user shell.
|
|
|
|
.It
|
|
|
|
Invoke
|
|
|
|
.Xr rcorder 8
|
2000-07-17 19:29:01 +04:00
|
|
|
to order the files in
|
2000-04-28 10:10:54 +04:00
|
|
|
.Pa /etc/rc.d/
|
2000-08-22 12:53:17 +04:00
|
|
|
that do not have a
|
|
|
|
.Dq nostart
|
|
|
|
keyword (refer to
|
2003-06-30 14:44:47 +04:00
|
|
|
.Xr rcorder 8 Ns 's
|
2001-09-06 03:53:22 +04:00
|
|
|
.Fl s
|
2000-08-22 12:53:17 +04:00
|
|
|
flag),
|
2000-04-28 10:10:54 +04:00
|
|
|
and assigns the result to a variable.
|
|
|
|
.It
|
2007-04-06 17:57:08 +04:00
|
|
|
Calls each script in turn using
|
|
|
|
.Fn run_rc_script
|
|
|
|
(from
|
2002-03-22 07:32:10 +03:00
|
|
|
.Xr rc.subr 8 ) ,
|
2000-04-28 10:10:54 +04:00
|
|
|
which sets
|
|
|
|
.Dv $1
|
|
|
|
to
|
|
|
|
.Sq start ,
|
2017-10-15 00:21:51 +03:00
|
|
|
and sources the script in a sub-shell.
|
2000-04-28 10:10:54 +04:00
|
|
|
If the script has a
|
|
|
|
.Sq .sh
|
|
|
|
suffix then it is sourced directly into the current shell.
|
2009-09-11 22:17:04 +04:00
|
|
|
.It
|
|
|
|
The output from the above steps is sent to a post-processor.
|
|
|
|
If
|
|
|
|
.Sy rc_silent
|
|
|
|
is false, then the post-processor displays the output.
|
|
|
|
If
|
|
|
|
.Sy rc_silent
|
|
|
|
is true, then the post-processor invokes the command specified in
|
|
|
|
.Va rc_silent_cmd
|
|
|
|
once for each line, without otherwise displaying the output.
|
|
|
|
Useful values for
|
|
|
|
.Va rc_silent_cmd
|
|
|
|
include
|
|
|
|
.Dq \&:
|
|
|
|
to display nothing at all, and
|
|
|
|
.Dq twiddle
|
|
|
|
to display a spinning symbol on the console.
|
|
|
|
Regardless of the value of
|
|
|
|
.Sy rc_silent ,
|
|
|
|
the post-processor saves the output in
|
|
|
|
.Pa /var/run/rc.log .
|
2000-04-28 10:10:54 +04:00
|
|
|
.El
|
|
|
|
.Ss Operation of rc.shutdown
|
|
|
|
.Bl -enum
|
|
|
|
.It
|
|
|
|
Source
|
|
|
|
.Pa /etc/rc.subr
|
2002-03-22 07:32:10 +03:00
|
|
|
to load various
|
|
|
|
.Xr rc.subr 8
|
|
|
|
shell functions to use.
|
2000-04-28 10:10:54 +04:00
|
|
|
.It
|
|
|
|
Invoke
|
|
|
|
.Xr rcorder 8
|
2000-07-17 19:29:01 +04:00
|
|
|
to order the files in
|
|
|
|
.Pa /etc/rc.d/
|
|
|
|
that have a
|
|
|
|
.Dq shutdown
|
2000-07-26 09:29:15 +04:00
|
|
|
keyword (refer to
|
2003-06-30 14:44:47 +04:00
|
|
|
.Xr rcorder 8 Ns 's
|
2001-09-06 03:53:22 +04:00
|
|
|
.Fl k
|
2000-07-26 09:29:15 +04:00
|
|
|
flag),
|
2000-04-28 10:10:54 +04:00
|
|
|
reverses that order, and assigns the result to a variable.
|
|
|
|
.It
|
2007-04-06 17:57:08 +04:00
|
|
|
Calls each script in turn using
|
|
|
|
.Fn run_rc_script
|
|
|
|
(from
|
2002-03-22 07:32:10 +03:00
|
|
|
.Xr rc.subr 8 ) ,
|
2000-04-28 10:10:54 +04:00
|
|
|
which sets
|
|
|
|
.Dv $1
|
|
|
|
to
|
|
|
|
.Sq stop ,
|
2017-10-15 00:21:51 +03:00
|
|
|
and sources the script in a sub-shell.
|
2000-04-28 10:10:54 +04:00
|
|
|
If the script has a
|
|
|
|
.Sq .sh
|
|
|
|
suffix then it is sourced directly into the current shell.
|
|
|
|
.El
|
|
|
|
.Ss Contents of rc.d/
|
|
|
|
.Nm rc.d/
|
|
|
|
is located in
|
|
|
|
.Pa /etc/rc.d .
|
|
|
|
The following file naming conventions are currently used in
|
|
|
|
.Nm rc.d/ :
|
2002-04-18 15:14:33 +04:00
|
|
|
.Bl -tag -width ALLUPPERCASExx -offset indent
|
|
|
|
.It Pa ALLUPPERCASE
|
2000-04-28 10:10:54 +04:00
|
|
|
Scripts that are
|
|
|
|
.Sq placeholders
|
2002-04-18 15:14:33 +04:00
|
|
|
to ensure that certain operations are performed before others.
|
2000-11-17 08:00:26 +03:00
|
|
|
In order of startup, these are:
|
2002-04-18 15:14:33 +04:00
|
|
|
.Bl -tag -width NETWORKINGxx
|
|
|
|
.It Pa NETWORKING
|
2001-05-04 07:22:23 +04:00
|
|
|
Ensure basic network services are running, including general
|
|
|
|
network configuration
|
|
|
|
.Pq Pa network
|
|
|
|
and
|
2016-12-17 10:37:24 +03:00
|
|
|
.Pa dhcpcd .
|
2002-04-18 15:14:33 +04:00
|
|
|
.It Pa SERVERS
|
2001-05-04 07:22:23 +04:00
|
|
|
Ensure basic services (such as
|
2002-01-31 04:28:53 +03:00
|
|
|
.Pa NETWORKING ,
|
2001-05-04 07:22:23 +04:00
|
|
|
.Pa ppp ,
|
|
|
|
.Pa syslogd ,
|
|
|
|
and
|
|
|
|
.Pa kdc )
|
|
|
|
exist for services that start early (such as
|
|
|
|
.Pa named ) ,
|
|
|
|
because they're required by
|
|
|
|
.Pa DAEMON
|
|
|
|
below.
|
2002-04-18 15:14:33 +04:00
|
|
|
.It Pa DAEMON
|
2001-05-04 07:22:23 +04:00
|
|
|
Before all general purpose daemons such as
|
|
|
|
.Pa dhcpd ,
|
|
|
|
.Pa lpd ,
|
|
|
|
and
|
|
|
|
.Pa ntpd .
|
2002-04-18 15:14:33 +04:00
|
|
|
.It Pa LOGIN
|
2001-05-04 07:22:23 +04:00
|
|
|
Before user login services
|
|
|
|
.Pa ( inetd ,
|
|
|
|
.Pa telnetd ,
|
|
|
|
.Pa rshd ,
|
|
|
|
.Pa sshd ,
|
|
|
|
and
|
|
|
|
.Pa xdm ) ,
|
|
|
|
as well as before services which might run commands as users
|
|
|
|
.Pa ( cron ,
|
|
|
|
.Pa postfix ,
|
|
|
|
and
|
|
|
|
.Pa sendmail ) .
|
2000-04-28 10:10:54 +04:00
|
|
|
.El
|
2017-10-15 00:21:51 +03:00
|
|
|
.It Pa inline.sh
|
|
|
|
Scripts that are sourced into the current shell rather than a sub-shell
|
2002-04-18 15:14:33 +04:00
|
|
|
have a
|
|
|
|
.Sq Pa .sh
|
|
|
|
suffix.
|
2000-04-28 10:10:54 +04:00
|
|
|
Extreme care must be taken in using this, as the startup sequence will
|
2017-10-15 00:21:51 +03:00
|
|
|
terminate if the script causes the current shell process to terminate.
|
2000-08-22 12:53:17 +04:00
|
|
|
.Pa /etc/rc.d/bootconf.sh
|
|
|
|
uses this behaviour to allow the user to select a different
|
|
|
|
configuration (including
|
|
|
|
.Pa /etc/rc.conf )
|
|
|
|
early in the boot.
|
2017-10-15 00:21:51 +03:00
|
|
|
.It Pa service
|
|
|
|
Scripts that are sourced in a sub-shell.
|
2007-04-06 18:20:08 +04:00
|
|
|
The boot does not stop if such a script terminates with a non-zero status,
|
|
|
|
but a script can stop the boot if necessary by invoking the
|
|
|
|
.Fn stop_boot
|
|
|
|
function (from
|
|
|
|
.Xr rc.subr 8 ) .
|
2000-04-28 10:10:54 +04:00
|
|
|
.El
|
1993-03-21 12:45:37 +03:00
|
|
|
.Pp
|
2002-04-18 15:14:33 +04:00
|
|
|
Each script should contain
|
|
|
|
.Xr rcorder 8
|
|
|
|
keywords, especially an appropriate
|
|
|
|
.Dq PROVIDE
|
|
|
|
entry.
|
|
|
|
.Pp
|
2000-04-28 10:10:54 +04:00
|
|
|
The scripts are expected to support at least the following arguments:
|
|
|
|
.Bl -tag -width restart -offset indent
|
2002-04-18 15:14:33 +04:00
|
|
|
.It Sy start
|
2000-12-15 03:57:27 +03:00
|
|
|
Start the service.
|
|
|
|
This should check that the service is to be started as specified by
|
2000-04-28 10:10:54 +04:00
|
|
|
.Xr rc.conf 5 .
|
2001-05-04 07:22:23 +04:00
|
|
|
Also checks if the service is already running and refuses to start if
|
|
|
|
it is.
|
|
|
|
This latter check is not performed by standard
|
|
|
|
.Nx
|
|
|
|
scripts if the system is starting directly to multi-user mode, to
|
|
|
|
speed up the boot process.
|
2002-04-18 15:14:33 +04:00
|
|
|
.It Sy stop
|
2000-12-15 03:57:27 +03:00
|
|
|
If the service is to be started as specified by
|
2000-04-28 10:10:54 +04:00
|
|
|
.Xr rc.conf 5 ,
|
2000-12-15 03:57:27 +03:00
|
|
|
stop the service.
|
|
|
|
This should check that the service is running and complain if it's not.
|
2002-04-18 15:14:33 +04:00
|
|
|
.It Sy restart
|
|
|
|
Perform a
|
|
|
|
.Sy stop
|
|
|
|
then a
|
|
|
|
.Sy start .
|
|
|
|
.It Sy status
|
2001-05-04 07:22:23 +04:00
|
|
|
If the script starts a process (rather than performing a one-off
|
|
|
|
operation), show the status of the process.
|
|
|
|
Otherwise it's not necessary to support this argument.
|
2000-12-15 03:57:27 +03:00
|
|
|
Defaults to displaying the process ID of the program (if running).
|
2002-04-18 15:14:33 +04:00
|
|
|
.It Sy poll
|
|
|
|
If the script starts a process (rather than performing a one-off
|
|
|
|
operation), wait for the command to exit.
|
|
|
|
Otherwise it's not necessary to support this argument.
|
|
|
|
.It Sy rcvar
|
2001-05-04 07:22:23 +04:00
|
|
|
Display which
|
2002-03-22 07:32:10 +03:00
|
|
|
.Xr rc.conf 5
|
2001-05-04 07:22:23 +04:00
|
|
|
variables are used to control the startup of the service (if any).
|
2000-04-28 10:10:54 +04:00
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
Other arguments (such as
|
|
|
|
.Sq reload ,
|
|
|
|
.Sq dumpdb ,
|
|
|
|
etc) can be added if necessary.
|
|
|
|
.Pp
|
2004-01-06 03:52:24 +03:00
|
|
|
The argument may have one of the following prefixes to alter its operation:
|
|
|
|
.Bl -tag -width "force" -offset indent
|
|
|
|
.It Sy fast
|
|
|
|
Skip the check for an existing running process.
|
|
|
|
Sets
|
|
|
|
.Sy rc_fast=yes .
|
|
|
|
.It Sy force
|
|
|
|
Skips the
|
|
|
|
.Xr rc.conf 5
|
|
|
|
check, ignores a failure result from any of the prerequisite checks,
|
|
|
|
executes the command, and always returns a zero exit status.
|
|
|
|
Sets
|
|
|
|
.Sy rc_force=yes .
|
|
|
|
.It Sy one
|
|
|
|
Skips the
|
|
|
|
.Xr rc.conf 5
|
2004-01-06 17:46:11 +03:00
|
|
|
check, but performs all other prerequisite tests.
|
2004-01-06 03:52:24 +03:00
|
|
|
.El
|
|
|
|
.Pp
|
2007-04-06 17:57:08 +04:00
|
|
|
In order to simplify scripts, the
|
|
|
|
.Fn run_rc_command
|
|
|
|
function from
|
2002-03-22 07:32:10 +03:00
|
|
|
.Xr rc.subr 8
|
2000-04-28 10:10:54 +04:00
|
|
|
may be used.
|
|
|
|
.Sh FILES
|
|
|
|
.Bl -tag -width /etc/rc.shutdown -compact
|
|
|
|
.It Pa /etc/rc
|
|
|
|
Startup script called by
|
|
|
|
.Xr init 8 .
|
|
|
|
.It Pa /etc/rc.d/
|
|
|
|
Directory containing control scripts for each service.
|
2010-05-14 20:19:58 +04:00
|
|
|
.It Pa /etc/rc.local
|
|
|
|
Local startup script.
|
2000-04-28 10:10:54 +04:00
|
|
|
.It Pa /etc/rc.shutdown
|
|
|
|
Shutdown script called by
|
|
|
|
.Xr shutdown 8 .
|
|
|
|
.It Pa /etc/rc.subr
|
2002-03-22 07:32:10 +03:00
|
|
|
Contains
|
|
|
|
.Xr rc.subr 8
|
|
|
|
functions used by various scripts.
|
|
|
|
.It Pa /etc/rc.conf
|
|
|
|
System startup configuration file.
|
2009-09-11 22:17:04 +04:00
|
|
|
.It Pa /var/run/rc.log
|
|
|
|
Log file created by
|
|
|
|
.Nm .
|
2000-04-28 10:10:54 +04:00
|
|
|
.El
|
1993-03-21 12:45:37 +03:00
|
|
|
.Sh SEE ALSO
|
1999-12-08 03:04:38 +03:00
|
|
|
.Xr rc.conf 5 ,
|
2000-04-28 10:10:54 +04:00
|
|
|
.Xr init 8 ,
|
2002-02-25 15:05:13 +03:00
|
|
|
.Xr rc.subr 8 ,
|
2000-04-28 10:10:54 +04:00
|
|
|
.Xr rcorder 8 ,
|
1993-03-21 12:45:37 +03:00
|
|
|
.Xr reboot 8 ,
|
2000-07-05 19:45:28 +04:00
|
|
|
.Xr shutdown 8
|
2010-04-14 14:03:18 +04:00
|
|
|
.Rs
|
|
|
|
.%A Luke Mewburn
|
|
|
|
.%T The Design and Implementation of the NetBSD rc.d system
|
|
|
|
.%I USENIX Association
|
|
|
|
.%B Proceedings of the FREENIX Track: 2001 USENIX Annual Technical Conference
|
|
|
|
.%D June 25-30, 2001
|
2010-04-14 17:07:19 +04:00
|
|
|
.%U http://www.usenix.org/publications/library/proceedings/usenix01/freenix01/full_papers/mewburn/mewburn.pdf
|
2010-04-14 14:03:18 +04:00
|
|
|
.Re
|
1993-03-21 12:45:37 +03:00
|
|
|
.Sh HISTORY
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
command appeared in
|
|
|
|
.Bx 4.0 .
|
2000-04-28 10:10:54 +04:00
|
|
|
The
|
|
|
|
.Pa /etc/rc.d
|
2000-08-22 12:53:17 +04:00
|
|
|
support was implemented in
|
|
|
|
.Nx 1.5
|
2003-02-14 18:20:17 +03:00
|
|
|
by
|
|
|
|
.An Luke Mewburn
|
|
|
|
.Aq lukem@NetBSD.org .
|
2009-09-11 22:17:04 +04:00
|
|
|
The post-processor, support for
|
|
|
|
.Va rc_silent ,
|
|
|
|
and saving output to a file, was implemented in
|
|
|
|
.Nx 6.0
|
|
|
|
by
|
|
|
|
.An Alan Barrett .
|