Hello:
I wanted a “watchdog” for Wireguard (entware) withCoreELEC, to:
a) Ping the server from the CoreELEC client (example of server: 10.1.1.1)
b) In the case that the ping does NOT work (probably for the dynamic public IP of the server), restart wg0
Something like this:
Entware WG has a file:
wireguard_watchdog
in:
/storage/.opt/bin
That should work in this way.
But, when I execute the file:
sh wireguard_watchdog
wireguard_watchdog: line 15: /lib/functions.sh: No such file or directory
I tried these script options too:
#!/bin/bash
while true
do
sleep 15
ping -c 1 10.1.1.1
if [ $? != 0 ]
then
wg-quick down wg0
sleep 4
wg-quick up wg0
fi
done
#!/bin/bash
tries=0
while [[ $tries -lt 3 ]]
do
if /bin/ping -c 1 10.1.1.1
then
# echo "wg working"
logger -n winterfell -i -t "wg-watchdog" -p user.notice "wireguard working"
exit 0
fi
## echo "wg fail"
tries=$((tries+1))
done
#echo "restarting wg"
wg-quick down wg0
sleep 4
wg-quick up wg0
logger -n winterfell -i -t "wg-watchdog" -p user.notice "wireguard restarted"
I tried to “simulate” scripts found with google for this purpose, but in these options there are script errors and scripts don’t work for me.
That’s my problem: I know what I want to do, but I don’t know enough about scripts to obtain a good result.
Anybody figures out how to to that (ping WG server from client and, if server does NOT “respond”, wg-quick down wg0 / wg-quick up wg0 to restart the connection from a new public IP of the server)?
Entware WG is great, because it solves DDNS names like “myhost.ddns.com”, but it has a problem: once that it solves (at start) a DDNS name, it does NOT solve it again, even if WG connection with server is lost.
I wanted a script to make it “automatic” and make a crontab task.
Thanks in advance and kind regards.