diff --git a/lib/rdk/NM_Dispatcher.sh b/lib/rdk/NM_Dispatcher.sh index 97b76055..cfaa0726 100644 --- a/lib/rdk/NM_Dispatcher.sh +++ b/lib/rdk/NM_Dispatcher.sh @@ -107,9 +107,15 @@ interfaceName=$1 interfaceStatus=$2 if [ "$interfaceStatus" = "up" ]; then - + /usr/bin/nm-online -q -t 60 # If Network manager is not online wait for 60 sec. TODO: Revisit this during connectivity check enable time CON_STATE=$(nmcli -t -f GENERAL.STATE device show "$interfaceName" 2>/dev/null | cut -d: -f2) NMdispatcherLog "Connection state of interface $interfaceName=$CON_STATE" + if [ "$CON_STATE" = "100 (connected)" ] || [ "$CON_STATE" = "120 (connected (site only))" ]; then + NMdispatcherLog "Connection state of $interfaceName is connected." + sh /lib/rdk/connectivitycheck.sh & + else + NMdispatcherLog "Connection state of $interfaceName Up But Not Fully connected." + fi fi if [ "x$interfaceName" != "x" ] && [ "$interfaceName" != "lo" ]; then diff --git a/lib/rdk/connectivitycheck.sh b/lib/rdk/connectivitycheck.sh new file mode 100644 index 00000000..341b3e99 --- /dev/null +++ b/lib/rdk/connectivitycheck.sh @@ -0,0 +1,79 @@ +#!/bin/sh +#################################################################################### +# If not stated otherwise in this file or this component's LICENSE file the +# following copyright and licenses apply: +# +# Copyright 2024 Comcast Cable Communications Management, LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#################################################################################### + +. /etc/include.properties +. /etc/device.properties + +if [ -f /lib/rdk/t2Shared_api.sh ]; then + source /lib/rdk/t2Shared_api.sh +fi + +CONNCHECK_LOG_FILE="$LOG_PATH/NMMonitor.log" +CONNCHECK_FILE="/tmp/connectivity_check_done" +CONNCHECK_TIMEOUT=120 # 2 minutes +CONNCHECK_RETRY_INTERVAL=10 # 10 seconds + +connectivityCheckLog() +{ + echo "$(/bin/timestamp) : $0: $*" >> $CONNCHECK_LOG_FILE +} + +if [ -n "$CONNECTIVITY_CHECK_URL" ]; then + URL="$CONNECTIVITY_CHECK_URL" +else + connectivityCheckLog "CONNECTIVITY_CHECK_URL not set. Exiting." + if [ ! -f $CONNCHECK_FILE ]; then + touch $CONNCHECK_FILE + fi + t2CountNotify "SYST_WARN_connectivitycheck_nourl_set" + exit 0 +fi + +# Get start time from /proc/uptime (integer part only) +START=$(cut -d. -f1 /proc/uptime) + +while true; do + NOW=$(cut -d. -f1 /proc/uptime) + ELAPSED=$((NOW - START)) + + if [ "$ELAPSED" -ge "$CONNCHECK_TIMEOUT" ]; then + connectivityCheckLog "Failed to get HTTP 204 within $CONNCHECK_TIMEOUT seconds." + if [ ! -f $CONNCHECK_FILE ]; then + touch $CONNCHECK_FILE + fi + t2CountNotify "SYST_WARN_connectivitycheck_time_expire" + exit 0 + fi + + HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" "$URL") + + if [ "$HTTP_CODE" -eq 204 ]; then + connectivityCheckLog "Connected: Received HTTP 204" + if [ ! -f $CONNCHECK_FILE ]; then + touch $CONNCHECK_FILE + fi + t2CountNotify "SYST_INFO_connectivitycheck_success" + exit 0 + else + connectivityCheckLog "connectivitycheck.sh Not connected yet (HTTP $HTTP_CODE). Retrying in $CONNCHECK_RETRY_INTERVAL seconds..." + fi + + sleep $CONNCHECK_RETRY_INTERVAL +done diff --git a/systemd_units/coredump-secure-upload.service b/systemd_units/coredump-secure-upload.service index 325d5592..20b9641e 100644 --- a/systemd_units/coredump-secure-upload.service +++ b/systemd_units/coredump-secure-upload.service @@ -21,8 +21,8 @@ [Unit] Description=COREDUMP UPLOAD -After=network-online.target tr69hostif.service -Requires=network-online.target +After=network-up.target tr69hostif.service +Requires=network-up.target [Service] ExecStart=/lib/rdk/uploadDumps.sh "" 1 secure diff --git a/systemd_units/coredump-upload.service b/systemd_units/coredump-upload.service index eeb4a0ca..fcddd9e0 100644 --- a/systemd_units/coredump-upload.service +++ b/systemd_units/coredump-upload.service @@ -19,8 +19,8 @@ [Unit] Description=COREDUMP UPLOAD -After=network-online.target -Requires=network-online.target +After=network-up.target +Requires=network-up.target [Service] ExecStart=/lib/rdk/uploadDumps.sh "" 1 diff --git a/systemd_units/minidump-secure-upload.service b/systemd_units/minidump-secure-upload.service index 86ff5115..cb875d14 100644 --- a/systemd_units/minidump-secure-upload.service +++ b/systemd_units/minidump-secure-upload.service @@ -20,8 +20,8 @@ [Unit] Description=MINIDUMP UPLOAD -After=network-online.target tr69hostif.service -Requires=network-online.target +After=network-up.target tr69hostif.service +Requires=network-up.target [Service] ExecStart=/lib/rdk/uploadDumps.sh "" 0 secure diff --git a/systemd_units/minidump-upload.service b/systemd_units/minidump-upload.service index dcb38dd4..9a2c3516 100644 --- a/systemd_units/minidump-upload.service +++ b/systemd_units/minidump-upload.service @@ -20,8 +20,8 @@ [Unit] Description=MINIDUMP UPLOAD -After=network-online.target -Requires=network-online.target +After=network-up.target +Requires=network-up.target [Service] ExecStart=/lib/rdk/uploadDumps.sh "" 0 diff --git a/systemd_units/notify-network-ready.service b/systemd_units/notify-network-ready.service deleted file mode 100644 index 8a11c9af..00000000 --- a/systemd_units/notify-network-ready.service +++ /dev/null @@ -1,8 +0,0 @@ -[Unit] -Description=Log Internet connectivity and Trigger network target -After=dbus.service - -[Service] -Type=oneshot -ExecStartPre=/bin/touch /tmp/connectivity_check_done -ExecStart=/lib/rdk/logMilestone.sh "INTERNET_FULLY_CONNECTED"