Commit b6f56e68 authored by Franco Fichtner's avatar Franco Fichtner

rc: batch-run bootup command before starting services; closes #1699

(cherry picked from commit 1b970b37)
parent 5f54b54b
...@@ -37,13 +37,15 @@ for RC_CONF in $(find /etc/rc.conf.d -type f); do ...@@ -37,13 +37,15 @@ for RC_CONF in $(find /etc/rc.conf.d -type f); do
. ${RC_CONF} . ${RC_CONF}
done done
# probe all deamons in /usr/local/etc/rc.d/ rc_enabled()
ls /usr/local/etc/rc.d/[a-z]* /etc/rc.d/[a-z]* | while read rc_filename; do {
rc_filename=${1}
name=${2}
# check if service has a name # check if service has a name
eval "$(grep "^name[[:blank:]]*=" ${rc_filename})"
if [ -z "${name}" ]; then if [ -z "${name}" ]; then
echo "Error: no name set in ${rc_filename}" echo "Error: no name set in ${rc_filename}"
continue return 1
fi fi
# check if service has a variable # check if service has a variable
...@@ -51,21 +53,42 @@ ls /usr/local/etc/rc.d/[a-z]* /etc/rc.d/[a-z]* | while read rc_filename; do ...@@ -51,21 +53,42 @@ ls /usr/local/etc/rc.d/[a-z]* /etc/rc.d/[a-z]* | while read rc_filename; do
if [ -z "${rcvar}" ]; then if [ -z "${rcvar}" ]; then
# FreeBSD does this, leave here for debugging # FreeBSD does this, leave here for debugging
#echo "Error: no rcvar set in $rc_filename" #echo "Error: no rcvar set in $rc_filename"
continue return 1
fi fi
# check if service is enabled # check if service is enabled
eval "enabled=\$${rcvar}" eval "enabled=\$${rcvar}"
if [ "${enabled}" == "YES" ]; then if [ "${enabled}" != "YES" ]; then
# run our bootstrap command on startup return 1
if [ "${1}" == "start" ]; then fi
pre_run_var="${name}_opnsense_bootup_run"
eval "pre_run_cmd=\$${pre_run_var}" return 0
if [ -n "${pre_run_cmd}" ]; then }
${pre_run_cmd}
fi rc_filenames="$(ls /etc/rc.d/[a-z]* /usr/local/etc/rc.d/[a-z]* 2> /dev/null || true)"
# run our bootstrap command on startup
if [ "${1}" == "start" ]; then
for rc_filename in ${rc_filenames}; do
eval "$(grep "^name[[:blank:]]*=" ${rc_filename})"
if ! rc_enabled ${rc_filename} ${name}; then
continue
fi fi
# pass all commands to script now
${rc_filename} ${1} pre_run_var="${name}_opnsense_bootup_run"
eval "pre_run_cmd=\$${pre_run_var}"
${pre_run_cmd}
done
fi
# pass all commands to script now
for rc_filename in ${rc_filenames}; do
eval "$(grep "^name[[:blank:]]*=" ${rc_filename})"
if ! rc_enabled ${rc_filename} ${name}; then
continue
fi fi
${rc_filename} ${1}
done done
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment