Skip to content

Commit 3edcfbc

Browse files
committed
rc: add ${name}_setup script support
Run a service-based setup script before running the start command. Useful for automatic configuration file generation.
1 parent a26d606 commit 3edcfbc

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

libexec/rc/rc.subr

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,8 @@ check_startmsgs()
795795
#
796796
# ${name}_prepend n Command added before ${command}.
797797
#
798+
# ${name}_setup n Command executed before ${command}.
799+
#
798800
# ${name}_login_class n Login class to use, else "daemon".
799801
#
800802
# ${name}_limits n limits(1) to apply to ${command}.
@@ -979,8 +981,8 @@ run_rc_command()
979981
_group=\$${name}_group _groups=\$${name}_groups \
980982
_fib=\$${name}_fib _env=\$${name}_env \
981983
_prepend=\$${name}_prepend _login_class=\${${name}_login_class:-daemon} \
982-
_limits=\$${name}_limits _oomprotect=\$${name}_oomprotect \
983-
_env_file=\$${name}_env_file
984+
_limits=\$${name}_limits _oomprotect=\$${name}_oomprotect \
985+
_setup=\$${name}_setup _env_file=\$${name}_env_file
984986

985987
if [ -n "$_env_file" ] && [ -r "${_env_file}" ]; then # load env from file
986988
set -a
@@ -1135,6 +1137,12 @@ $command $rc_flags $command_args"
11351137
fi
11361138
fi
11371139

1140+
if [ -n "$_setup" ]; then
1141+
if ! _run_rc_doit "$_setup"; then
1142+
warn "failed to setup ${name}"
1143+
fi
1144+
fi
1145+
11381146
# Prepend default limits
11391147
_doit="$_cd limits -C $_login_class $_limits $_doit"
11401148

@@ -2151,7 +2159,7 @@ check_kern_features()
21512159
# check_namevarlist var
21522160
# Return "0" if ${name}_var is reserved in rc.subr.
21532161

2154-
_rc_namevarlist="program chroot chdir env flags fib nice user group groups prepend"
2162+
_rc_namevarlist="program chroot chdir env flags fib nice user group groups prepend setup"
21552163
check_namevarlist()
21562164
{
21572165
local _v

0 commit comments

Comments
 (0)