-
-
Save namxam/784aafd29fa3554c8bb3c40dc25ac314 to your computer and use it in GitHub Desktop.
wireguard watchdog script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# 1. Save file to system /usr/bin | |
# 2. Make it executable | |
# 3. Add crontab entry: | |
# sudo su | |
# crontab -e | |
# Add `* * * * * /usr/bin/wg-watchdog` | |
# | |
# You can track history via `journalctl -f -t wg-watchdog` | |
tries=0 | |
while [[ $tries -lt 3 ]] | |
do | |
# Ping wireguard vpn gateway | |
if /bin/ping -c 1 10.254.0.1 | |
then | |
# Notify that we are online | |
logger -i -t "wg-watchdog" -p user.notice "wireguard online" | |
exit 0 | |
fi | |
# Notify that we are offline | |
logger -i -t "wg-watchdog" -p user.notice "wireguard offline" | |
tries=$((tries+1)) | |
done | |
# Restart service to reconnect | |
sudo systemctl restart wg-quick@wg0 | |
logger -i -t "wg-watchdog" -p user.notice "wireguard restarted" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment