From acc95f2f23b8697ebccd89c61247bc254fdf6fb4 Mon Sep 17 00:00:00 2001 From: Fotis Panagiotopoulos <46975045+fjpanag@users.noreply.github.com> Date: Fri, 3 Nov 2023 11:35:48 +0200 Subject: [PATCH] fix: restart service if no gateway is found (#13) This should fix #12 --- libs/core.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libs/core.sh b/libs/core.sh index 326a85d..5595fa5 100755 --- a/libs/core.sh +++ b/libs/core.sh @@ -108,6 +108,15 @@ function get_def_gw { if [ "$(cat /sys/class/net/wlan0/operstate)" == "up" ]; then default_gw="$(ip route | awk 'NR==1 {print $3}')" echo "${default_gw}" + if [ -z "$default_gw" ]; then + log_msg "WARN: Cannot get the default gateway. Restarting service..." + sleep 5 + systemctl restart sonar.service + fi + else + log_msg "WARN: Network is not ready yet. Restarting service..." + sleep 5 + systemctl restart sonar.service fi }