modem-restart: Add connectivity checks

This commit is contained in:
Xavier Del Campo Romero 2023-08-04 12:11:21 +02:00
parent abec0ce751
commit d8c72fbb2f
Signed by: xavi
GPG Key ID: 84FF3612A9BF43F2

View File

@ -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