Skip to content

Commit

Permalink
rc: add ${name}_setup script support
Browse files Browse the repository at this point in the history
Run a service-based setup script before running the start command.
Useful for automatic configuration file generation.

Reviewed by:	https://reviews.freebsd.org/D36006

(cherry picked from commit c9be47b34dd847da1d4ab0feee4a6100b2c5ea0d)
  • Loading branch information
fichtner authored and laffer1 committed Dec 9, 2023
1 parent 4372c4c commit c09e53c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions libexec/rc/rc.subr
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,8 @@ check_startmsgs()
#
# ${name}_prepend n Command added before ${command}.
#
# ${name}_setup n Command executed before ${command}.
#
# ${name}_login_class n Login class to use, else "daemon".
#
# ${name}_limits n limits(1) to apply to ${command}.
Expand Down Expand Up @@ -966,8 +968,8 @@ run_rc_command()
_group=\$${name}_group _groups=\$${name}_groups \
_fib=\$${name}_fib _env=\$${name}_env \
_prepend=\$${name}_prepend _login_class=\${${name}_login_class:-daemon} \
_limits=\$${name}_limits _oomprotect=\$${name}_oomprotect \
_env_file=\$${name}_env_file
_limits=\$${name}_limits _oomprotect=\$${name}_oomprotect \
_setup=\$${name}_setup _env_file=\$${name}_env_file

if [ -n "$_env_file" ] && [ -r "${_env_file}" ]; then # load env from file
set -a
Expand Down Expand Up @@ -1122,6 +1124,12 @@ $command $rc_flags $command_args"
fi
fi

if [ -n "$_setup" ]; then
if ! _run_rc_doit "$_setup"; then
warn "failed to setup ${name}"
fi
fi

# Prepend default limits
_doit="$_cd limits -C $_login_class $_limits $_doit"

Expand Down Expand Up @@ -2138,7 +2146,7 @@ check_kern_features()
# check_namevarlist var
# Return "0" if ${name}_var is reserved in rc.subr.

_rc_namevarlist="program chroot chdir env flags fib nice user group groups prepend"
_rc_namevarlist="program chroot chdir env flags fib nice user group groups prepend setup"
check_namevarlist()
{
local _v
Expand Down

0 comments on commit c09e53c

Please sign in to comment.