Skip to content

Instantly share code, notes, and snippets.

@mattkasun
Created October 31, 2020 13:50
Show Gist options
  • Select an option

  • Save mattkasun/9a0e90d9d31b2c935d3f6d6e71dbece9 to your computer and use it in GitHub Desktop.

Select an option

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

I have a one-liner in cron
*/1 * * * * root if ! /bin/ping -c 1 10.10.10.11; then systemctl restart wg-quick@wg9; fi

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