aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-08-04 12:11:21 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-08-04 12:11:21 +0200
commitd8c72fbb2f4262573a0e2a8e2aee487742931b0f (patch)
tree415bedad2990fdba0cfec60cec79eaab2a7d6c14
parentabec0ce751412ed08795a6705fd7c2b3b64504d6 (diff)
modem-restart: Add connectivity checks
-rwxr-xr-xmodem-restart29
1 files changed, 28 insertions, 1 deletions
diff --git a/modem-restart b/modem-restart
index 422ca54..13e73ac 100755
--- a/modem-restart
+++ b/modem-restart
@@ -18,7 +18,28 @@ is_data_available()
return 0
}
+connectivity()
+{
+ if nmcli c show --active | grep wlan0; then
+ return 0
+ fi
+
+ if [ $COUNTER -ge 10 ]; then
+ COUNTER=0
+ if ping -q -W5 -c1 -s0 libredns.gr; then
+ return 0
+ else
+
+ return 1
+ fi
+ fi
+
+ COUNTER=$((COUNTER + 1))
+ return 0
+}
+
TRY=0
+COUNTER=0
while :; do
if ! is_modem_available ; then
TRY=$((TRY + 1))
@@ -30,8 +51,14 @@ while :; do
TRY=0
elif ! is_data_available; then
echo $(date): Restarting mobile data
- systemd-inhibit --what=sleep --why="Restart mobile data" sleep 5
+ nmcli c down internet
nmcli c up internet
+ systemd-inhibit --what=sleep --why="Restart mobile data" sleep 5
+ elif ! connectivity; then
+ echo $(date): Connectivity test failed. Restaring modem...
+ systemctl restart eg25-manager
+ systemd-inhibit --what=sleep --why="modem reset" sleep 60
+ TRY=$((TRY + 1))
fi
sleep 5