Implement ``one'' prefix to allow a "one shot" operation as if
${rcvar}=yes yet all the other prerequisite tests are still performed. The existing ``force'' prefix is a sledgehammer that ignores all the prerequisite checks and always returns a zero exit status; this is a more gentle approach to the problem of "manipulate this disabled service without editing rc.conf(5)".
This commit is contained in:
parent
d27168eb15
commit
f3bab2a8fc
24
etc/rc.subr
24
etc/rc.subr
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: rc.subr,v 1.60 2003/07/26 05:13:47 lukem Exp $
|
||||
# $NetBSD: rc.subr,v 1.61 2004/01/06 00:52:24 lukem Exp $
|
||||
#
|
||||
# Copyright (c) 1997-2002 The NetBSD Foundation, Inc.
|
||||
# All rights reserved.
|
||||
|
@ -252,6 +252,7 @@ wait_for_pids()
|
|||
# ------ ---------
|
||||
# fast Skip the pid check, and set rc_fast=yes
|
||||
# force Set ${rcvar} to YES, and set rc_force=yes
|
||||
# one Set ${rcvar} to YES
|
||||
#
|
||||
# The following globals are used:
|
||||
#
|
||||
|
@ -368,7 +369,7 @@ wait_for_pids()
|
|||
#
|
||||
# Variable Purpose
|
||||
# -------- -------
|
||||
# rc_arg Argument to command, after fast/force processing
|
||||
# rc_arg Argument to command, after fast/force/one processing
|
||||
# performed
|
||||
#
|
||||
# rc_flags Flags to start the default command with.
|
||||
|
@ -390,14 +391,23 @@ run_rc_command()
|
|||
err 3 'run_rc_command: $name is not set.'
|
||||
fi
|
||||
|
||||
_rc_prefix=
|
||||
case "$rc_arg" in
|
||||
fast*) # "fast" prefix; don't check pid
|
||||
rc_arg=${rc_arg#fast}
|
||||
rc_fast=yes
|
||||
;;
|
||||
force*) # "force prefix; always start
|
||||
rc_arg=${rc_arg#force}
|
||||
force*) # "force" prefix; always run
|
||||
rc_force=yes
|
||||
_rc_prefix=force
|
||||
rc_arg=${rc_arg#${_rc_prefix}}
|
||||
if [ -n "${rcvar}" ]; then
|
||||
eval ${rcvar}=YES
|
||||
fi
|
||||
;;
|
||||
one*) # "one" prefix; set ${rcvar}=yes
|
||||
_rc_prefix=one
|
||||
rc_arg=${rc_arg#${_rc_prefix}}
|
||||
if [ -n "${rcvar}" ]; then
|
||||
eval ${rcvar}=YES
|
||||
fi
|
||||
|
@ -642,8 +652,8 @@ $command $rc_flags $command_args"
|
|||
fi
|
||||
_rc_restart_done=true
|
||||
|
||||
( $0 ${rc_force:+force}stop )
|
||||
$0 ${rc_force:+force}start
|
||||
( $0 ${_rc_prefix}stop )
|
||||
$0 ${_rc_prefix}start
|
||||
|
||||
eval $_postcmd
|
||||
;;
|
||||
|
@ -748,7 +758,7 @@ load_rc_config()
|
|||
#
|
||||
rc_usage()
|
||||
{
|
||||
echo -n 1>&2 "Usage: $0 [fast|force]("
|
||||
echo -n 1>&2 "Usage: $0 [fast|force|one]("
|
||||
|
||||
_sep=
|
||||
for _elem; do
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
.\" $NetBSD: rc.8,v 1.26 2003/06/30 10:44:47 wiz Exp $
|
||||
.\" $NetBSD: rc.8,v 1.27 2004/01/06 00:52:24 lukem Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2000 The NetBSD Foundation, Inc.
|
||||
.\" Copyright (c) 2000-2004 The NetBSD Foundation, Inc.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to The NetBSD Foundation
|
||||
|
@ -34,7 +34,7 @@
|
|||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd April 18, 2002
|
||||
.Dd January 6, 2004
|
||||
.Dt RC 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
|
@ -249,21 +249,11 @@ 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.
|
||||
If
|
||||
.Sq forcestart
|
||||
is given, ignore the
|
||||
.Xr rc.conf 5
|
||||
check and start anyway.
|
||||
.It Sy stop
|
||||
If the service is to be started as specified by
|
||||
.Xr rc.conf 5 ,
|
||||
stop the service.
|
||||
This should check that the service is running and complain if it's not.
|
||||
If
|
||||
.Sq forcestop
|
||||
is given, ignore the
|
||||
.Xr rc.conf 5
|
||||
check and attempt to stop.
|
||||
.It Sy restart
|
||||
Perform a
|
||||
.Sy stop
|
||||
|
@ -289,6 +279,25 @@ Other arguments (such as
|
|||
.Sq dumpdb ,
|
||||
etc) can be added if necessary.
|
||||
.Pp
|
||||
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
|
||||
check, but perform all other prerequisite tests.
|
||||
.El
|
||||
.Pp
|
||||
In order to simplify scripts, the run_rc_command() function from
|
||||
.Xr rc.subr 8
|
||||
may be used.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
.\" $NetBSD: rc.subr.8,v 1.11 2003/05/06 10:46:43 jmmv Exp $
|
||||
.\" $NetBSD: rc.subr.8,v 1.12 2004/01/06 00:52:24 lukem Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2002 The NetBSD Foundation, Inc.
|
||||
.\" Copyright (c) 2002-2004 The NetBSD Foundation, Inc.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to The NetBSD Foundation
|
||||
|
@ -34,7 +34,7 @@
|
|||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd April 18, 2002
|
||||
.Dd January 6, 2004
|
||||
.Dt RC.SUBR 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
|
@ -248,7 +248,7 @@ with
|
|||
.Ar commands
|
||||
being the list of valid arguments
|
||||
prefixed by
|
||||
.Dq "[fast|force]" .
|
||||
.Dq "[fast|force|one]" .
|
||||
.It Ic reverse_list Ar item Op Ar ...
|
||||
Print the list of
|
||||
.Ar items
|
||||
|
@ -267,26 +267,57 @@ scripts to be implemented in a small amount of shell code.
|
|||
.Ar argument
|
||||
is searched for in the list of supported commands, which may be one
|
||||
of:
|
||||
.Dl start stop restart rcvar
|
||||
as well as any word listed in the optional variable
|
||||
.Sy extra_commands .
|
||||
.Bl -tag -width restart -offset indent
|
||||
.It Sy start
|
||||
Start the service.
|
||||
This should check that the service is to be started as specified by
|
||||
.Xr rc.conf 5 .
|
||||
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.
|
||||
.It Sy stop
|
||||
If the service is to be started as specified by
|
||||
.Xr rc.conf 5 ,
|
||||
stop the service.
|
||||
This should check that the service is running and complain if it's not.
|
||||
.It Sy restart
|
||||
Perform a
|
||||
.Sy stop
|
||||
then a
|
||||
.Sy start .
|
||||
Defaults to displaying the process ID of the program (if running).
|
||||
.It Sy rcvar
|
||||
Display which
|
||||
.Xr rc.conf 5
|
||||
variables are used to control the startup of the service (if any).
|
||||
.El
|
||||
.Pp
|
||||
If
|
||||
.Sy pidfile
|
||||
or
|
||||
.Sy procname
|
||||
is set, also allow:
|
||||
.Dl status poll
|
||||
is set, also support:
|
||||
.Bl -tag -width restart -offset indent
|
||||
.It Sy poll
|
||||
Wait for the command to exit.
|
||||
.It Sy status
|
||||
Show the status of the process.
|
||||
.El
|
||||
.Pp
|
||||
Other supported commands are listed in the optional variable
|
||||
.Sy extra_commands .
|
||||
.Pp
|
||||
.Ar argument
|
||||
may have one of the following prefixes which alters its operation:
|
||||
.Bl -tag -width "Prefix" -offset indent -compact
|
||||
.It Sy Prefix
|
||||
.Sy Operation
|
||||
.It Li fast
|
||||
.Bl -tag -width "Prefix" -offset indent
|
||||
.It Sy fast
|
||||
Skip the check for an existing running process,
|
||||
and sets
|
||||
.Sy rc_fast=YES .
|
||||
.It Li force
|
||||
.It Sy force
|
||||
Skip the checks for
|
||||
.Sy rcvar
|
||||
being set to yes,
|
||||
|
@ -296,7 +327,11 @@ This ignores
|
|||
.Ar argument Ns Sy _precmd
|
||||
returning non-zero, and ignores any of the
|
||||
.Sy required_*
|
||||
tests failing .
|
||||
tests failing, and always returns a zero exit status.
|
||||
.It Sy one
|
||||
Skip the checks for
|
||||
.Sy rcvar
|
||||
being set to yes, but performs all the other prerequisite tests.
|
||||
.El
|
||||
.Pp
|
||||
.Ic run_rc_command
|
||||
|
|
Loading…
Reference in New Issue