mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2025-06-21 02:05:40 +02:00
drop script 'rotate-ntp'
For RouterOS 6.x a separate package 'ntp' exists. This adds server functionality, but allows ip addresses for the client only. I added the script 'rotate-ntp' to update addresses from names... Now with RouterOS 7.x there's no extra package and the limitation does no longer exist. So let's just drop the script. This adds migration code, that... * removes the script from configuration * removes a scheduler from configuration * sets the configured ntp pool name for ntp client
This commit is contained in:
parent
66b7fccd30
commit
b3de1fad34
7 changed files with 9 additions and 97 deletions
|
@ -194,7 +194,6 @@ Available scripts
|
||||||
* [Visualize OSPF state via LEDs](doc/ospf-to-leds.md)
|
* [Visualize OSPF state via LEDs](doc/ospf-to-leds.md)
|
||||||
* [Manage system update](doc/packages-update.md)
|
* [Manage system update](doc/packages-update.md)
|
||||||
* [Run scripts on ppp connection](doc/ppp-on-up.md)
|
* [Run scripts on ppp connection](doc/ppp-on-up.md)
|
||||||
* [Rotate NTP servers](doc/rotate-ntp.md)
|
|
||||||
* [Act on received SMS](doc/sms-action.md)
|
* [Act on received SMS](doc/sms-action.md)
|
||||||
* [Forward received SMS](doc/sms-forward.md)
|
* [Forward received SMS](doc/sms-forward.md)
|
||||||
* [Import SSH keys](doc/ssh-keys-import.md)
|
* [Import SSH keys](doc/ssh-keys-import.md)
|
||||||
|
|
|
@ -1,43 +1,3 @@
|
||||||
Rotate NTP servers
|
This script has been dropped as the limitation does no longer exist with
|
||||||
==================
|
RouterOS 7.x, where you can enable a ntp server and use a name for the client
|
||||||
|
at the same time.
|
||||||
[◀ Go back to main README](../README.md)
|
|
||||||
|
|
||||||
> ℹ️ **Info**: This script can not be used on its own but requires the base
|
|
||||||
> installation. See [main README](../README.md) for details.
|
|
||||||
|
|
||||||
Description
|
|
||||||
-----------
|
|
||||||
|
|
||||||
RouterOS requires NTP servers to be configured by IP address. Servers from a
|
|
||||||
pool may appear and disappear, leaving broken NTP configuration.
|
|
||||||
|
|
||||||
This script allows to rotate IP addresses from a given pool.
|
|
||||||
|
|
||||||
Requirements and installation
|
|
||||||
-----------------------------
|
|
||||||
|
|
||||||
Just install the script:
|
|
||||||
|
|
||||||
$ScriptInstallUpdate rotate-ntp;
|
|
||||||
|
|
||||||
Configuration
|
|
||||||
-------------
|
|
||||||
|
|
||||||
The configuration goes to `global-config-overlay`, this is the parameter:
|
|
||||||
|
|
||||||
* `NtpPool`: dns name of ntp server pool
|
|
||||||
|
|
||||||
Usage and invocation
|
|
||||||
--------------------
|
|
||||||
|
|
||||||
Just run the script to update the NTP configuration with actual IP
|
|
||||||
addresses from pool if required.
|
|
||||||
|
|
||||||
Alternatively a scheduler can be created:
|
|
||||||
|
|
||||||
/system/scheduler/add interval=5d name=rotate-ntp on-event="/system/script/run rotate-ntp;" start-time=startup;
|
|
||||||
|
|
||||||
---
|
|
||||||
[◀ Go back to main README](../README.md)
|
|
||||||
[▲ Go back to top](#top)
|
|
||||||
|
|
|
@ -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 80;
|
:global GlobalConfigVersion 81;
|
||||||
|
|
||||||
# This is used for DNS and backup file.
|
# This is used for DNS and backup file.
|
||||||
:global Domain "example.com";
|
:global Domain "example.com";
|
||||||
|
@ -146,10 +146,6 @@
|
||||||
# add more here...
|
# add more here...
|
||||||
};
|
};
|
||||||
|
|
||||||
# This address should resolve ntp servers and is used to update
|
|
||||||
# ntp settings. A pool can rotate servers.
|
|
||||||
:global NtpPool "pool.ntp.org";
|
|
||||||
|
|
||||||
# This is the address used to send gps data to.
|
# This is the address used to send gps data to.
|
||||||
:global GpsTrackUrl "https://example.com/index.php";
|
:global GpsTrackUrl "https://example.com/index.php";
|
||||||
|
|
||||||
|
|
|
@ -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 80;
|
:global GlobalConfigVersion 81;
|
||||||
|
|
||||||
# Copy configuration from global-config here and modify it.
|
# Copy configuration from global-config here and modify it.
|
||||||
|
|
||||||
|
|
|
@ -89,6 +89,7 @@
|
||||||
78="New documentation is online for notifications via Telegram & Matrix, variable inspection, ip address calculation and running scripts once.";
|
78="New documentation is online for notifications via Telegram & Matrix, variable inspection, ip address calculation and running scripts once.";
|
||||||
79="Introduced new script 'backup-partition' to save configuration to fallback partition.";
|
79="Introduced new script 'backup-partition' to save configuration to fallback partition.";
|
||||||
80="The 'routeros-v7' branch will now freeze, and vanish any time in future. You already switched to 'main' branch, well done!";
|
80="The 'routeros-v7' branch will now freeze, and vanish any time in future. You already switched to 'main' branch, well done!";
|
||||||
|
81="Dropped script 'rotate-ntp', as the limitation does no longer exist.";
|
||||||
};
|
};
|
||||||
|
|
||||||
# Migration steps to be applied on script updates
|
# Migration steps to be applied on script updates
|
||||||
|
@ -101,4 +102,5 @@
|
||||||
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;";
|
||||||
73=":global ScriptInstallUpdate; :global CharacterReplace; :foreach Old,New in={ \"cloud-backup\"=\"backup-cloud\"; \"email-backup\"=\"backup-email\"; \"upload-backup\"=\"backup-upload\" } do={ /system/script/set name=\$New [ find where name=\$Old ]; :foreach Scheduler in=[ /system/scheduler/find where on-event~\$Old ] do={ /system/scheduler/set \$Scheduler name=[ \$CharacterReplace [ get \$Scheduler name ] \$Old \$New ] on-event=[ \$CharacterReplace [ get \$Scheduler on-event ] \$Old \$New ]; }; }; \$ScriptInstallUpdate;";
|
73=":global ScriptInstallUpdate; :global CharacterReplace; :foreach Old,New in={ \"cloud-backup\"=\"backup-cloud\"; \"email-backup\"=\"backup-email\"; \"upload-backup\"=\"backup-upload\" } do={ /system/script/set name=\$New [ find where name=\$Old ]; :foreach Scheduler in=[ /system/scheduler/find where on-event~\$Old ] do={ /system/scheduler/set \$Scheduler name=[ \$CharacterReplace [ get \$Scheduler name ] \$Old \$New ] on-event=[ \$CharacterReplace [ get \$Scheduler on-event ] \$Old \$New ]; }; }; \$ScriptInstallUpdate;";
|
||||||
|
81=":global NtpPool; :if ([ :len [ /system/script/find where name=\"rotate-ntp\" ] ] > 0) do={ /system/script/remove [ find where name=\"rotate-ntp\" ]; /system/scheduler/remove [ find where name=\"rotate-ntp\" ]; /system/ntp/client/set servers=\$NtpPool; };";
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
:local 0 "global-functions";
|
:local 0 "global-functions";
|
||||||
|
|
||||||
# expected configuration version
|
# expected configuration version
|
||||||
:global ExpectedConfigVersion 80;
|
:global ExpectedConfigVersion 81;
|
||||||
|
|
||||||
# global variables not to be changed by user
|
# global variables not to be changed by user
|
||||||
:global GlobalFunctionsReady false;
|
:global GlobalFunctionsReady false;
|
||||||
|
@ -1260,14 +1260,6 @@
|
||||||
:global TimeIsSync;
|
:global TimeIsSync;
|
||||||
|
|
||||||
:while ([ $TimeIsSync ] = false) do={
|
:while ([ $TimeIsSync ] = false) do={
|
||||||
:if ([ :len [ /system/script/find where name="rotate-ntp" ] ] > 0 && \
|
|
||||||
([ /system/resource/get uptime ] % (180 * 1000000000)) = 0s) do={
|
|
||||||
:do {
|
|
||||||
/system/script/run rotate-ntp;
|
|
||||||
} on-error={
|
|
||||||
$LogPrintExit2 debug $0 ("Running rotate-ntp failed.") false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
:delay 1s;
|
:delay 1s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
39
rotate-ntp
39
rotate-ntp
|
@ -1,39 +1,2 @@
|
||||||
#!rsc by RouterOS
|
#!rsc by RouterOS
|
||||||
# RouterOS script: rotate-ntp
|
# dummy for removal
|
||||||
# Copyright (c) 2013-2022 Christian Hesse <mail@eworm.de>
|
|
||||||
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
|
|
||||||
#
|
|
||||||
# rotate the ntp servers
|
|
||||||
# https://git.eworm.de/cgit/routeros-scripts/about/doc/rotate-ntp.md
|
|
||||||
|
|
||||||
:local 0 "rotate-ntp";
|
|
||||||
:global GlobalFunctionsReady;
|
|
||||||
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
|
|
||||||
|
|
||||||
:global NtpPool;
|
|
||||||
:global RotateNtpResolveFailed;
|
|
||||||
|
|
||||||
:global LogPrintExit2;
|
|
||||||
|
|
||||||
:local Ntp1;
|
|
||||||
:local Ntp2;
|
|
||||||
|
|
||||||
:if ([ /system/ntp/client/get enabled ] != true) do={
|
|
||||||
$LogPrintExit2 warning $0 ("NTP client is not enabled!") true;
|
|
||||||
}
|
|
||||||
|
|
||||||
:do {
|
|
||||||
:set Ntp1 [ :resolve ("0." . $NtpPool) ];
|
|
||||||
:set Ntp2 [ :resolve ("1." . $NtpPool) ];
|
|
||||||
:set RotateNtpResolveFailed false;
|
|
||||||
} on-error={
|
|
||||||
:if ($RotateNtpResolveFailed != true) do={
|
|
||||||
:set RotateNtpResolveFailed true;
|
|
||||||
$LogPrintExit2 warning $0 ("Resolving NTP server failed.") true;
|
|
||||||
} else={
|
|
||||||
$LogPrintExit2 debug $0 ("Resolving NTP server failed, again.") true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$LogPrintExit2 info $0 ("Updating NTP servers to " . $Ntp1 . " and " . $Ntp2) false;
|
|
||||||
/system/ntp/client/set servers=($Ntp1, $Ntp2);
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue