From d8c72fbb2f4262573a0e2a8e2aee487742931b0f Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Fri, 4 Aug 2023 12:11:21 +0200 Subject: [PATCH] modem-restart: Add connectivity checks --- modem-restart | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) 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