firmware: allow launcher to operate on a random sleep if requested

To make verbatim script passthrough work we also need to introduce
a scripting option to reach the random sleep option afterwards.

We add a random delay of up to 25 minutes to the cron based operations
in order to give the update servers more room to breathe.
This commit is contained in:
Franco Fichtner 2021-11-16 13:21:10 +01:00
parent 82d21d0775
commit d2f9efcd69
3 changed files with 42 additions and 5 deletions

View File

@ -27,6 +27,6 @@
SUBR=/usr/local/etc/rc.firmware.subr
if ! /usr/local/opnsense/scripts/firmware/launcher.sh ${SUBR} "${@}"; then
if ! /usr/local/opnsense/scripts/firmware/launcher.sh -s ${SUBR} "${@}"; then
echo "A firmware action is currently in progress."
fi

View File

@ -43,8 +43,39 @@ update
upgrade
"
SELECTED=${1}
shift
DO_RANDOM=
DO_SCRIPT=
while getopts r:s: OPT; do
case ${OPT} in
r)
DO_RANDOM="-r $(jot -r 1 1 ${OPTARG})"
;;
s)
# make sure the script exists
if [ ! -f "${OPTARG}" ]; then
exit 1
fi
DO_SCRIPT="-s ${OPTARG}"
;;
*)
# ignore unknown
;;
esac
done
shift $((${OPTIND} - 1))
if [ -n "${DO_SCRIPT}" ]; then
SELECTED=${DO_SCRIPT#"-s "}
else
SELECTED=${1}
shift
fi
if [ -n "${DO_RANDOM}" ]; then
sleep ${DO_RANDOM#"-r "}
fi
if [ -f "${SELECTED}" ]; then
${FLOCK} ${LOCKFILE} ${SELECTED} "${@}"

View File

@ -9,6 +9,12 @@ command:/usr/local/opnsense/scripts/firmware/launcher.sh check
parameters:%s
type:script
message:Running firmware update status
[poll]
command:/usr/local/opnsense/scripts/firmware/launcher.sh -r 1500 check
parameters:%s
type:script
message:Running firmware update status via cron
description:Firmware update check
[flush]
@ -200,8 +206,8 @@ type:script
message:issued firmware power off
[auto-update]
command:/usr/local/etc/rc.firmware
command:/usr/local/etc/rc.firmware -r 1500
description:Automatic firmware update
parameters:%s
type:script
message:attempting automatic firmware update
message:Attempting automatic firmware update via cron