reintroduce global-wait

This commit is contained in:
Christian Hesse 2021-11-15 22:17:43 +01:00
parent 3b997d3087
commit 185fe2c730
9 changed files with 65 additions and 6 deletions

View file

@ -172,6 +172,7 @@ Available Scripts
* [Comment DHCP leases with info from access list](doc/dhcp-lease-comment.md) * [Comment DHCP leases with info from access list](doc/dhcp-lease-comment.md)
* [Create DNS records for DHCP leases](doc/dhcp-to-dns.md) * [Create DNS records for DHCP leases](doc/dhcp-to-dns.md)
* [Send backup via e-mail](doc/email-backup.md) * [Send backup via e-mail](doc/email-backup.md)
* [Wait for global functions und modules](doc/global-wait.md)
* [Send GPS position to server](doc/gps-track.md) * [Send GPS position to server](doc/gps-track.md)
* [Use WPA2 network with hotspot credentials](doc/hotspot-to-wpa.md) * [Use WPA2 network with hotspot credentials](doc/hotspot-to-wpa.md)
* [Create DNS records for IPSec peers](doc/ipsec-to-dns.md) * [Create DNS records for IPSec peers](doc/ipsec-to-dns.md)

40
doc/global-wait.md Normal file
View file

@ -0,0 +1,40 @@
Wait for global functions and modules
=====================================
[◀ Go back to main README](../README.md)
🛈 This script can not be used on its own but requires the base installation.
See [main README](../README.md) for details.
Description
-----------
The global functions from `global-functions` and modules are loaded by
scheduler at system startup. Running these functions at system startup may
result in race condition where configuration and/or function are not yet
available. This script is supposed to wait for everything being prepared.
Do **not** add this script `global-wait` to the `global-scripts` scheduler!
It would inhibit the initialization of configuration and functions.
Requirements and installation
-----------------------------
Just install the script:
$ScriptInstallUpdate global-wait;
... and add it to your scheduler, for example in combination with the module
to [manage VLANs on bridge ports](mod/bridge-port-vlan.md):
/ system scheduler add name=bridge-port-vlan on-event="/ system script run global-wait; :global BridgePortVlan; \$BridgePortVlan default;" start-time=startup;
See also
--------
* [Manage ports in bridge](mod/bridge-port-to.md)
* [Manage VLANs on bridge ports](mod/bridge-port-vlan.md)
---
[◀ Go back to main README](../README.md)
[▲ Go back to top](#top)

View file

@ -34,7 +34,8 @@ Also dhcp client can be handled:
Add a scheduler to start with default setup on system startup: Add a scheduler to start with default setup on system startup:
/ system scheduler add name=bridge-port-to on-event=":global GlobalFunctionsReady; :while (\$GlobalFunctionsReady != true) do={ :delay 500ms; }; :global BridgePortTo; \$BridgePortTo default;" start-time=startup; $ScriptInstallUpdate global-wait;
/ system scheduler add name=bridge-port-vlan on-event="/ system script run global-wait; :global BridgePortTo; \$BridgePortTo default;" start-time=startup;
Usage and invocation Usage and invocation
-------------------- --------------------
@ -72,6 +73,7 @@ configuration:
See also See also
-------- --------
* [Wait for global functions und modules](../global-wait.md)
* [Manage VLANs on bridge ports](bridge-port-vlan.md) * [Manage VLANs on bridge ports](bridge-port-vlan.md)
--- ---

View file

@ -39,7 +39,8 @@ Also dhcp client can be handled:
Add a scheduler to start with default setup on system startup: Add a scheduler to start with default setup on system startup:
/ system scheduler add name=bridge-port-vlan on-event=":global GlobalFunctionsReady; :while (\$GlobalFunctionsReady != true) do={ :delay 500ms; }; :global BridgePortVlan; \$BridgePortVlan default;" start-time=startup; $ScriptInstallUpdate global-wait;
/ system scheduler add name=bridge-port-vlan on-event="/ system script run global-wait; :global BridgePortVlan; \$BridgePortVlan default;" start-time=startup;
Usage and invocation Usage and invocation
-------------------- --------------------
@ -76,6 +77,7 @@ configuration:
See also See also
-------- --------
* [Wait for global functions und modules](../global-wait.md)
* [Manage ports in bridge](bridge-port-to.md) * [Manage ports in bridge](bridge-port-to.md)
--- ---

View file

@ -8,7 +8,7 @@
# Make sure all configuration properties are up to date and this # Make sure all configuration properties are up to date and this
# value is in sync with value in script 'global-functions'! # value is in sync with value in script 'global-functions'!
:global GlobalConfigVersion 67; :global GlobalConfigVersion 68;
# This is used for DNS and backup file. # This is used for DNS and backup file.
:global Domain "example.com"; :global Domain "example.com";

View file

@ -8,7 +8,7 @@
# Make sure all configuration properties are up to date and this # Make sure all configuration properties are up to date and this
# value is in sync with value in script 'global-functions'! # value is in sync with value in script 'global-functions'!
# Comment or remove to disable news and change notifications. # Comment or remove to disable news and change notifications.
:global GlobalConfigVersion 67; :global GlobalConfigVersion 68;
# Copy configuration from global-config here and modify it. # Copy configuration from global-config here and modify it.

View file

@ -71,6 +71,7 @@
65="Added module to manage VLANs on bridge ports."; 65="Added module to manage VLANs on bridge ports.";
66="Moved script 'bridge-port-to-default' to new module."; 66="Moved script 'bridge-port-to-default' to new module.";
67="Moved modules to directory with shorter name."; 67="Moved modules to directory with shorter name.";
68="Reintroduced 'global-wait' for functions in scheduler.";
}; };
# Migration steps to be applied on script updates # Migration steps to be applied on script updates
@ -79,7 +80,7 @@
47="/ certificate remove [ find where fingerprint=\"731d3d9cfaa061487a1d71445a42f67df0afca2a6c2d2f98ff7b3ce112b1f568\" or fingerprint=\"25847d668eb4f04fdd40b12b6b0740c567da7d024308eb6c2c96fe41d9de218d\" ];"; 47="/ certificate remove [ find where fingerprint=\"731d3d9cfaa061487a1d71445a42f67df0afca2a6c2d2f98ff7b3ce112b1f568\" or fingerprint=\"25847d668eb4f04fdd40b12b6b0740c567da7d024308eb6c2c96fe41d9de218d\" ];";
52=":global CertificateDownload; :if ([ :len [ / certificate find where fingerprint=\"67add1166b020ae61b8f5fc96813c04c2aa589960796865572a3c7e737613dfd\" or fingerprint=\"96bcec06264976f37460779acf28c5a7cfe8a3c0aae11a8ffcee05c0bddf08c6\" ] ] < 2) do={ \$CertificateDownload \"R3\"; }; / certificate remove [ find where fingerprint=\"0687260331a72403d909f105e69bcf0d32e1bd2493ffc6d9206d11bcd6770739\" ];"; 52=":global CertificateDownload; :if ([ :len [ / certificate find where fingerprint=\"67add1166b020ae61b8f5fc96813c04c2aa589960796865572a3c7e737613dfd\" or fingerprint=\"96bcec06264976f37460779acf28c5a7cfe8a3c0aae11a8ffcee05c0bddf08c6\" ] ] < 2) do={ \$CertificateDownload \"R3\"; }; / certificate remove [ find where fingerprint=\"0687260331a72403d909f105e69bcf0d32e1bd2493ffc6d9206d11bcd6770739\" ];";
54=":global ScriptInstallUpdate; :global TelegramTokenId; :global TelegramChatId; :if ([ :len \$TelegramTokenId ] > 0 && [ :len \$TelegramChatId ] > 0) do={ \$ScriptInstallUpdate mod/notification-telegram; }"; 54=":global ScriptInstallUpdate; :global TelegramTokenId; :global TelegramChatId; :if ([ :len \$TelegramTokenId ] > 0 && [ :len \$TelegramChatId ] > 0) do={ \$ScriptInstallUpdate mod/notification-telegram; }";
61="/ system script remove [ find where name~\"^(early-errors|global-wait|mode-button-(event|scheduler)|script-updates)\\\$\" source~\"^#!rsc by RouterOS\\n\" ];"; 61="/ system script remove [ find where name~\"^(early-errors|mode-button-(event|scheduler)|script-updates)\\\$\" source~\"^#!rsc by RouterOS\\n\" ];";
66=":global ScriptInstallUpdate; :if ([ :len [ / system script find where name=\"bridge-port-to-default\" ] ] > 0) do={ / system script remove [ find where name~\"^bridge-port-to(-default|ggle)\\\$\" ]; \$ScriptInstallUpdate mod/bridge-port-to; }"; 66=":global ScriptInstallUpdate; :if ([ :len [ / system script find where name=\"bridge-port-to-default\" ] ] > 0) do={ / system script remove [ find where name~\"^bridge-port-to(-default|ggle)\\\$\" ]; \$ScriptInstallUpdate mod/bridge-port-to; }";
67=":global ScriptInstallUpdate; :global CharacterReplace; :foreach Script in=[ / system script find where name~\"^global-functions.d/\" ] do={ / system script set name=[ \$CharacterReplace [ / system script get \$Script name ] \"global-functions.d/\" \"mod/\" ] \$Script; }; \$ScriptInstallUpdate;"; 67=":global ScriptInstallUpdate; :global CharacterReplace; :foreach Script in=[ / system script find where name~\"^global-functions.d/\" ] do={ / system script set name=[ \$CharacterReplace [ / system script get \$Script name ] \"global-functions.d/\" \"mod/\" ] \$Script; }; \$ScriptInstallUpdate;";
}; };

View file

@ -8,7 +8,7 @@
# https://git.eworm.de/cgit/routeros-scripts/about/ # https://git.eworm.de/cgit/routeros-scripts/about/
# expected configuration version # expected configuration version
:global ExpectedConfigVersion 67; :global ExpectedConfigVersion 68;
# global variables not to be changed by user # global variables not to be changed by user
:global GlobalFunctionsReady false; :global GlobalFunctionsReady false;

13
global-wait Normal file
View file

@ -0,0 +1,13 @@
#!rsc by RouterOS
# RouterOS script: global-wait
# Copyright (c) 2020-2021 Christian Hesse <mail@eworm.de>
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
#
# provides: backup-script
#
# wait for global-functions to finish
# https://git.eworm.de/cgit/routeros-scripts/about/doc/global-wait.md
:local 0 "global-wait";
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }