add script 'global-wait'

Run this in schedulers that fire on startup without interval. Schedulers
should look something like this:

/ system scheduler {
  add name=global-scripts on-event="/ system script { run global-config; run global-config-overlay; run global-functions; }" start-time=startup;
  add name=bridge-port-to-default on-event="/ system script { run global-wait; run bridge-port-to-default; }" start-time=startup;
}
This commit is contained in:
Christian Hesse 2020-03-12 08:40:29 +01:00
parent 63ed093340
commit 98585afe1c
3 changed files with 17 additions and 2 deletions

View file

@ -9,6 +9,7 @@
:global ExpectedConfigVersion 13;
# global variables not to be changed by user
:global GlobalFunctionsReady false;
:global Identity [ / system identity get name ];
:global SentConfigChangesNotification "-";
:global SentLteFirmwareUpgradeNotification "-";
@ -524,3 +525,6 @@
:delay 1s;
}
}
# signal we are ready
:set GlobalFunctionsReady true;

11
global-wait Normal file
View file

@ -0,0 +1,11 @@
#!rsc
# RouterOS script: global-wait
# Copyright (c) 2020 Christian Hesse <mail@eworm.de>
#
# wait for global-functions to finish
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={
:delay 500ms;
}

View file

@ -36,9 +36,9 @@
:if ($SchedulerVal->"name" != "global-scripts" && \
$SchedulerVal->"start-time" = "startup" && \
$SchedulerVal->"interval" = 0s && \
[ :pick ($SchedulerVal->"on-event") 0 7 ] != ":delay ") do={
!(($SchedulerVal->"on-event") ~ "\\brun global-wait\\b")) do={
$LogPrintExit warning ("Scheduler " . $SchedulerVal->"name" . " starts on startup, " . \
"without interval. Add delay to make sure the configuration is available!") false;
"without waiting for global-functions. Run 'global-wait' to avoid race conditions!") false;
}
}