Skip to content

Instantly share code, notes, and snippets.

@mattkasun
Created October 31, 2020 13:50
Show Gist options
  • Save mattkasun/9a0e90d9d31b2c935d3f6d6e71dbece9 to your computer and use it in GitHub Desktop.
Save mattkasun/9a0e90d9d31b2c935d3f6d6e71dbece9 to your computer and use it in GitHub Desktop.
wireguard watchdog script
#!/bin/bash
tries=0
while [[ $tries -lt 3 ]]
do
if /bin/ping -c 1 10.200.200.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"
sudo systemctl restart wg-quick@wg0
logger -n winterfell -i -t "wg-watchdog" -p user.notice "wireguard restarted"
#crontab entry
#*/15 * * * * /home/mkasun/bin/wg-watchdog.sh
@linux-helmut
Copy link

it's not working for me! (Linux 5.10.0-20-amd64)
the exit 0 at line 10 leef the while-do-down loop but not the srcipt.
if the ping fails or not the restart run everyon.

here is my script thats work for for me:

#!/bin/bash

if /bin/ping -c 1 xxx.xxx.xxx.xxx
then
exit 0
else
systemctl restart wg-quick@wg0
fi

crontab entry:
#Watchdog für Wireguard wg0 (VPN Tunnel)
*/5 * * * * root /opt/wg-watchdog.sh >/dev/null 2>&1
@reboot root sleep 10;/opt/wg-watchdog.sh >/dev/null 2>&1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment