rc.subr —
functions for rc.d scripts
. /etc/rc.subr
check_pidfile pidfile
procname |
|
force_depend script
[var] |
|
run_rc_command command
[argument ...] |
|
The functions of FreeBSD's
rc.subr are built into
init_sh(8), so that
rc(8) scripts written for it run
unchanged. . /etc/rc.subr is accepted and has no
effect in init_sh(8); a script
started by any other shell re-runs itself under
init_sh(8).
A typical script:
#!/sbin/init_sh
#
# PROVIDE: food
# REQUIRE: DAEMON
# KEYWORD: shutdown
. /etc/rc.subr
name="food"
rcvar="food_enable"
command="/usr/sbin/food"
pidfile="/var/run/food.pid"
load_rc_config $name
run_rc_command "$1"
checkyesno
var
- Exit 0 if the variable var is “YES”,
“TRUE”, “ON” or “1”, and 1 if it
is “NO”, “FALSE”, “OFF” or
“0”, in any case. Any other value is reported and counts as
no.
check_pidfile
pidfile procname
- Print the process ID in pidfile if that process
exists and is running procname.
check_process
procname
- Print the IDs of the processes running
procname.
debug
message
- Print message on the standard error if
rc_debug is enabled.
err
exitval message
- Print message on the standard error and exit with
status exitval.
force_depend
script
- Start the service
/etc/rc.d/script if it is
not running, whether or not it is enabled.
info
message
- Print message if rc_info is
enabled.
load_rc_config
[name]
- Load /etc/defaults/rc.conf and the files in
rc_conf_files, once, and then
/etc/rc.conf.d/name if it
exists. The files are read, not run: see
rc.conf(5).
run_rc_command
command [argument ...]
- Carry out command, as described in
rc(8), using the variables below.
wait_for_pids
pid ...
- Wait until the processes have exited.
warn
message
- Print message on the standard error.
run_rc_command uses these variables:
- name
- The service's name. Required.
- rcvar
- The rc.conf(5) variable enabling
the service. If empty, the service is always enabled.
- command
- The program to start, followed by ${name}_flags from
rc.conf(5) (or
flags) and command_args.
${name}_program overrides it.
- pidfile
- The file holding the running service's process ID.
- procname
- The program name that identifies the running service; defaults to
command.
- sig_stop
- The signal that stops the service; default
TERM.
- extra_commands
- Commands besides the standard ones.
- required_dirs,
required_files
- Must exist for the service to start.
- ${command}_cmd
- Replaces the built-in handling of command.
- ${command}_precmd,
${command}_postcmd
- Run before and after command. A failing
_precmd stops the command.
rc.subr first appeared in
NetBSD 1.3. These built-ins were written for
OxideBSD.
${name}_user is not supported yet.