| RC.SUBR(8) | System Manager's Manual | RC.SUBR(8) |
rc.subr — daemon
control scripts routines
daemon=path_to_executable |
. |
/etc/rc.d/rc.subr |
rc_cmd |
action |
Apart from a few notable exceptions, rc scripts must follow this naming policy:
daemon it
is referring to.Every script under /etc/rc.d follows this pattern:
rc.subr, which defines default shell
functions and variable values.rc_* functions and set the
rc_bg or rc_reload variables,
if needed.rc_pre and/or
rc_post function, if needed.rc_cmd function as “rc_cmd
$1”.The following shell functions are defined by
rc.subr:
rc_checkrc_cmd
actionrc.d script, based on the settings of various
shell variables. rc_cmd is extremely flexible, and
allows fully functional rc.d scripts to be
implemented in a small amount of shell code. For a given
action, if the rc_${action}
function is not defined, then a default function is provided by
rc.subr. In addition actions can be disabled by
setting the rc_${action} variable to
“NO”. For example, if “rc_reload=NO” is set in
the rc.d script, and
rc_cmd is called for the reload action, an error
will be raised. Similarly, the special variable
rc_usercheck must be set to “NO” if
the check action requires
root privileges.
The action argument can be
start, stop,
reload, restart, or
check:
checkrc_check. Return 0 if the daemon is
running or 1 if it is not.startrc_check. If it's not running, call
rc_pre if it exists, then
rc_start.stoprc_check. If it is running, call
rc_stop and wait up to 30 seconds for the
daemon to properly shutdown. If successful, run
rc_post if it exists.restartstop, then if successful run
start.reloadrc_check. If it is running, call
rc_reload.rc_configteststart,
reload and restart if
implemented by the rc.d(8)
script.rc_execrc_poststop if implemented by
the rc.d(8) script.rc_prestart if implemented
by the rc.d(8) script.rc_reloadSIGHUP to a daemon will
have the desired effect, i.e. that it will reload its configuration.rc_startrc_exec "${daemon} ${daemon_flags}"
rc_stoprc_cmd uses the following shell variables
to control its behaviour.
rc.subr without defining
daemon first.rc.subr itself. It searches
login.conf(5) for a login
class that has the same name as the rc.d script
itself and uses that. If no such login class exists then
“daemon” will be used.rc_exec.start,
stop and reload actions to
return. This is only guaranteed with the default
rc_start, rc_stop and
rc_reload functions.rc.d script has to redefine this
variable
after
sourcing rc.subr.YES in an
rc.d script to force starting the daemon in
background when using the default rc_start.rc.d script
to disable the reload action if the respective daemon does not support
reloading its configuration.
The same is
possible, but almost never useful, for other actions.rc_reload() function. Defaults to
HUP.rc_stop() function. Default to
TERM.rc.d
script, if the check action needs root
privileges.All daemon_* variables are set in the following ways:
rc.subr:
daemon_class=daemon daemon_execdir= daemon_flags= daemon_logger= daemon_rtable=0 daemon_timeout=30 daemon_user=root
rc.d script
before sourcing
rc.subr, thus overriding the global defaults.rc.d scripts.rc.d script.The rc.subr framework first appeared in
OpenBSD 4.9.
The rc.subr framework was written by
Robert Nagy
<robert@openbsd.org>,
Antoine Jacoutot
<ajacoutot@openbsd.org>,
and Ingo Schwarze
<schwarze@openbsd.org>.
| October 22, 2022 | openbsd |