Last active
June 14, 2022 17:11
-
-
Save shvchk/fd40e386ef073ee3c9fff7bbc2e5879f to your computer and use it in GitHub Desktop.
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
#! /usr/bin/env sh | |
host="" | |
wait=10 | |
max_tries=3 | |
# -------------------- | |
log="logger -t wg-if-up" | |
host_up="false" | |
try=1 | |
while :; do | |
case $host_up in | |
true) | |
while ping -c 1 -W 1 $host &> /dev/null; do | |
try=1 | |
sleep $wait | |
done | |
$log "No connection to $host detected (try $try)" | |
if [ $try -lt $max_tries ]; then | |
try=$(( try + 1 )) | |
continue | |
fi | |
host_up="false" | |
/etc/storage/wireguard/client.sh stop | |
;; | |
false) | |
until ping -c 1 -W 1 $host &> /dev/null; do | |
sleep $wait | |
done | |
try=1 | |
host_up="true" | |
/etc/storage/wireguard/client.sh start | |
;; | |
esac | |
$log "Host $host up: $host_up" | |
sleep $wait | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment