2021-10-14 06:52:03 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-10-14 07:02:01 +00:00
|
|
|
if [[ -e "/var/lib/bundlewrap/hard-${node.name}/info" ]]
|
|
|
|
then
|
|
|
|
# make sure we're not restarting during bw apply
|
|
|
|
echo "bw apply running"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2021-10-14 06:52:03 +00:00
|
|
|
now="$(date +%s)"
|
|
|
|
|
|
|
|
everything_up=1
|
|
|
|
|
|
|
|
% for peer, ip in sorted(peers.items()):
|
|
|
|
# ${peer}
|
2021-10-30 17:36:20 +00:00
|
|
|
if ! /usr/bin/ping -c 4 ${ip} >/dev/null
|
2021-10-14 06:52:03 +00:00
|
|
|
then
|
2021-10-30 17:36:20 +00:00
|
|
|
echo "${peer} was not reachable!" >&2
|
2021-10-14 06:52:03 +00:00
|
|
|
everything_up=0
|
|
|
|
fi
|
|
|
|
|
|
|
|
% endfor
|
|
|
|
if [[ "$everything_up" -eq 1 ]]
|
|
|
|
then
|
|
|
|
echo "Everything is up as expected"
|
|
|
|
echo "$now" > /var/tmp/wg_all_reached
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
five_min_ago="$(expr $now - 300)"
|
|
|
|
last_reached="$(cat /var/tmp/wg_all_reached)"
|
|
|
|
|
|
|
|
if [[ "$last_reached" -lt "$five_min_ago" ]]
|
|
|
|
then
|
2021-10-30 17:36:20 +00:00
|
|
|
echo "RESTART" >&2
|
2021-10-14 06:52:03 +00:00
|
|
|
|
|
|
|
systemctl restart systemd-networkd
|
|
|
|
|
|
|
|
# only restart once an hour
|
|
|
|
echo "$(expr $now + 3300)" > /var/tmp/wg_all_reached
|
|
|
|
elif [[ "$last_reached" -gt "$now" ]]
|
|
|
|
then
|
|
|
|
echo "Something's broken, but we have recently restarted"
|
|
|
|
else
|
|
|
|
echo "Something's broken, but still in grace time"
|
|
|
|
fi
|