RC.SUBR(8) | MidnightBSD System Manager's Manual | RC.SUBR(8) |
rc.subr
—
functions used by system shell scripts
.
/etc/rc.subr
backup_file
action file
current backupcheckyesno
varcheck_pidfile
pidfile procname
[interpreter]check_process
procname [interpreter]debug
messageerr
exitval messageforce_depend
nameinfo
messageload_kld
[-e
regex]
[-m
module]
fileload_rc_config
[service]load_rc_config_var
name varmount_critical_filesystems
typerc_usage
command ...reverse_list
item ...run_rc_command
argumentrun_rc_script
file argumentwait_for_pids
[pid ...]warn
messageThe rc.subr
script contains commonly used
shell script functions and variable definitions which are used by various
scripts such as rc(8).
Scripts required by ports in /usr/local/etc/rc.d
will also eventually be rewritten to make use of it.
The rc.subr
functions were mostly imported
from NetBSD.
They are accessed by sourcing /etc/rc.subr into the current shell.
The following shell functions are available:
backup_file
action file current backupThe action argument may be one of the following:
add
update
remove
checkyesno
varYES
”,
“TRUE
”,
“ON
”, or
‘1
’. Return 1 if
var is defined to
“NO
”,
“FALSE
”,
“OFF
”, or
‘0
’. Otherwise, warn that
var is not set correctly. The values are case
insensitive. Note: var should be a
variable name, not its value; checkyesno
will
expand the variable by itself.check_pidfile
pidfile procname
[interpreter]#! interpreter [...]
and use interpreter with its optional arguments and procname appended as the process string to search for.
check_process
procname [interpreter]check_pidfile
.debug
message: DEBUG:
”, and then message. This function is
intended to be used by developers as an aid to debugging scripts. It can
be turned on or off by the
rc.conf(5) variable
rc_debug.err
exitval messageexit
with an exit value of
exitval. The error message consists of the script
name (from $0), followed by
“: ERROR:
”, and then
message.force_depend
nameforce_depend
currently). If the script fails for
any reason it will output a warning and return with a return value of 1.
If it was successful it will return 0.info
message: INFO:
”, and then
message. The display of this informational output
can be turned on or off by the
rc.conf(5) variable
rc_info.load_kld
[-e
regex]
[-m
module]
file-m
, or an
egrep(1) regular
expression matching the module name can be supplied via
-e
. By default, the module is assumed to have the
same name as file, which is not always the
case.load_rc_config
[service]run_rc_command
arguments defined by the calling script, to provide an easy mechanism for
an administrator to override the behaviour of a given
rc.d(8) script without
requiring the editing of that script.load_rc_config_var
name varload_rc_config
in a
sub-shell to prevent unwanted side effects from other variable
assignments.mount_critical_filesystems
typerc_usage
command ...fast
|force
|one
|quiet
]”.reverse_list
item ...run_rc_command
argumentrun_rc_command
is extremely flexible, and allows
fully functional rc.d(8)
scripts to be implemented in a small amount of shell code.
argument is searched for in the list of supported commands, which may be one of:
start
stop
restart
stop
then a
start
. Defaults to displaying the process ID
of the program (if running).enabled
rcvar
If pidfile or procname is set, also support:
Other supported commands are listed in the optional variable extra_commands.
argument may have one of the following prefixes which alters its operation:
fast
YES
.force
YES
”, and sets
rc_force=YES
. This
ignores argument_precmd
returning non-zero, and ignores any of the
required_* tests failing, and always returns a
zero exit status.one
YES
”, but performs all the
other prerequisite tests.quiet
check_startmsgs
inside
rc.subr
) and errors about usage of services
that are not enabled in
rc.conf(5). This
prefix also sets
rc_quiet=YES
.
Note: rc_quiet is not intended
to completely mask all debug and warning messages, but only certain
small classes of them.run_rc_command
uses the following
shell variables to control its behaviour. Unless otherwise stated, these
are optional.
checkyesno
to determine if this method should
be run.#! command_interpreter
[...]
which results in its ps(1) command being:
command_interpreter [...]
command
so use that string to find the PID(s) of the running command rather than command.
check_pidfile $pidfile
$procname
to find the PID. Otherwise, if command is set, use:
check_process
$procname
to find the PID.
start
method.start
method.start
method. This is done after invoking the
commands from start_precmd so that the missing
modules are not loaded in vain if the preliminary commands indicate a
error condition. A word in the list can have an optional
“:
modname”
or
“~
pattern”
suffix. The modname or
pattern parameter is passed to
load_kld
through a -m
or -e
option, respectively. See the
description of load_kld
in this document for
details.checkyesno
on each of the list
variables before running the start
method.cd
to before running
command, if ${name}_chroot
is not provided.flags
’ can
be used to override this.daemon
”.YES
” is used, no
child processes are protected. If
“ALL
”, protect all child
processes.stop
method. Defaults to
SIGTERM
.reload
method. Defaults to
SIGHUP
.For a given method argument, if
argument_cmd is not defined,
then a default method is provided by
run_rc_command
:
start
checkyesno
rcvar
succeeds, start command.stop
check_pidfile
or
check_process
(as appropriate),
kill
sig_stop those
PIDs, and run wait_for_pids
on those
PIDs.reload
stop
, except that it uses
sig_reload instead, and does not run
wait_for_pids
. Another difference from
stop
is that reload
is
not provided by default. It can be enabled via
extra_commands if appropriate:
extra_commands=reload
restart
stop
method, then the
start
method.status
poll
rcvar
NO
”.The following variables are available to the methods (such as
argument_cmd) as well as
after run_rc_command
has completed:
run_rc_command
, after
fast and force processing has been performed.flags
’.
This variable may be changed by the
argument_precmd
method.fast
” prefix was
used.force
” prefix was
used.run_rc_script
file argumentVarious shell variables are unset before file is started:
The startup behaviour of file depends upon the following checks:
stop_boot
[always]yes
’ (see
rc(8) to learn more about
autoboot), or checkyesno
always indicates a truth value, then a
SIGTERM
signal is sent to the parent process,
which is assumed to be
rc(8). Otherwise, the shell
exits with a non-zero status.wait_for_pids
[pid ...]warn
message: WARNING:
”, and then
message.rc.subr
file resides in
/etc.The rc.subr
script appeared in
NetBSD 1.3. The
rc.d(8) support functions
appeared in NetBSD 1.5. The
rc.subr
script first appeared in
FreeBSD 5.0.
March 18, 2022 | midnightbsd-3.1 |