ℹ️ Info: This script can not be used on its own but requires the base installation of RouterOS scripts from eworm-de.
This script restarts (disable/enable) a wireguard peer interface if no handshake is ok in 3 minutes. If you want it will notify about the restart. I've created it because when my mikrotik restarts or there is a dinamic ip change, wireguard interfaces sometimes don't connect and stay in this state forever. Restart only happens if there is fully connectivity (default gateway is reachable, dns is resolving, time is in sync).
Just install the script:
$ScriptInstallUpdate wireguard-restart "base-url=https://raw.githubusercontent.com/martindb/routeros/main/";
Then add a scheduler to run it periodically:
/system/scheduler/add interval=3m name=wireguard-restart on-event="/system/script/run wireguard-restart;" start-time=startup;
The wireguard peer to be checked/restarted needs autorestart
word in the comment.
If you want to receive a notification every time it's restarted, add notify
label also.
A typical comment should look like:
"autorestart, notify"
Also notification settings are required for e-mail, matrix and/or telegram.