From fb789e7d52cc67d3f5a3e713a355e121e772ebcb Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Sat, 10 Oct 2020 20:08:55 +0200 Subject: initial commit --- reboot-if-no-net-connection | 23 +++++++++++++++++++++++ reboot-if-no-net-connection.service | 7 +++++++ reboot-if-no-net-connection.timer | 10 ++++++++++ 3 files changed, 40 insertions(+) create mode 100755 reboot-if-no-net-connection create mode 100644 reboot-if-no-net-connection.service create mode 100644 reboot-if-no-net-connection.timer diff --git a/reboot-if-no-net-connection b/reboot-if-no-net-connection new file mode 100755 index 0000000..bb8c43d --- /dev/null +++ b/reboot-if-no-net-connection @@ -0,0 +1,23 @@ +#!/bin/bash + +for i in {1..300}; do + + default_gateway=$( + ip route \ + | sed ' + s/^default\s\+\S\+\s\+\(\S\+\)\s.*$/\1/ + t + d + ' + ) + + if [ -n "${default_gateway}" ] \ + && ping -c1 "${default_gateway}" >/dev/null 2>&1; then + exit + fi + + sleep 1 + +done + +reboot diff --git a/reboot-if-no-net-connection.service b/reboot-if-no-net-connection.service new file mode 100644 index 0000000..cbc0f06 --- /dev/null +++ b/reboot-if-no-net-connection.service @@ -0,0 +1,7 @@ +[Unit] +Description=check net connectivity - reboot in case of error +After=network-online.target + +[Service] +Type=oneshot +ExecStart=/usr/bin/reboot-if-no-net-connection diff --git a/reboot-if-no-net-connection.timer b/reboot-if-no-net-connection.timer new file mode 100644 index 0000000..5c39d47 --- /dev/null +++ b/reboot-if-no-net-connection.timer @@ -0,0 +1,10 @@ +[Unit] +Description=repeatedly check net connectivity + +[Timer] +RandomizedDelaySec=1min +OnUnitInactiveSec=10min +OnBootSec=10min + +[Install] +WantedBy=timers.target -- cgit v1.2.3