#! /usr/bin/env sh
host="у меня тут адрес сервера"
wait=10
max_tries=3
up_cmd="ifup wg0"
down_cmd="ifdown wg0"
# --------------------
log="logger -t wg-if-up"
host_status="down"
try=1
err=""
[ -n "$host" ] || err="No host specified"
[ -n "$up_cmd" ] || err="No up command specified"
[ -n "$down_cmd" ] || err="No down command specified"
[ -z "$err" ] || { $log "$err"; exit 1; }
while :; do
case $host_status in
up)
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_status="down"
$down_cmd
;;
down)
until ping -c 1 -W 1 $host > /dev/null; do
sleep $wait
done
try=1
host_status="up"
$up_cmd
;;
esac
$log "Host $host $host_status"
sleep $wait
этот скрипт добавлен в автозагрузку сюда
ifup (wg0) имя интерфейса wireguard
Автор скрипта
shvchk