Skip to content

Commit 88df3a1

Browse files
Added new self heal script for ethagent (#95)
RDKB-62792: As a workaround to mitigate [RDKB-62729](https://ccp.sys.comcast.net/browse/RDKB-62729), ethagent self-heal is added. The following steps are done: - Check eth wan enabled status, if it is true, list of interfaces is [1,2,3] (or) it is [1,2,3,4] - Fetch total number of ethernet devices associated from eth_api command (eth_api CcspHalExtSw_getAssociatedDevice) - Fetch and calculate sum of associated devices per interface using dmcli (dmcli eRT getv Device.Ethernet.Interface.1.X_RDKCENTRAL-COM_AssociatedDeviceNumberOfEntries) - If eth_api and dmcli sum values mismatch, trigger restart of ethagent process This ethagent script is triggered from selfheal_bootup.sh script Unit Test: [RDKB-62792_unit_test_logs.rtf](https://github.com/user-attachments/files/24224901/RDKB-62792_unit_test_logs.rtf) --------- Co-authored-by: Santosh Nayak <70348540+snayak002c@users.noreply.github.com>
1 parent c2b007e commit 88df3a1

File tree

2 files changed

+148
-0
lines changed

2 files changed

+148
-0
lines changed

scripts/ethagent_associated_dev.sh

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#!/bin/sh
2+
3+
UTOPIA_PATH="/etc/utopia/service.d"
4+
LOG_FILE="/rdklogs/logs/EthAgentSelfHeal.log"
5+
6+
SERVICE="CcspEthAgent"
7+
DMCLI="dmcli eRT getv"
8+
ETH_API="/usr/bin/eth_api CcspHalExtSw_getAssociatedDevice"
9+
LOG_PREFIX="[EthAgentSelfHeal]"
10+
11+
# Ensure log directory exists
12+
mkdir -p /rdklogs/logs
13+
14+
# Source RDK logger
15+
source $UTOPIA_PATH/log_capture_path.sh
16+
17+
# Redirect ALL stdout/stderr of this script to our log file
18+
exec >> "$LOG_FILE" 2>&1
19+
20+
log() {
21+
echo_t "$LOG_PREFIX $*"
22+
}
23+
24+
# -----------------------
25+
# Get eth_wan mode
26+
# -----------------------
27+
get_ethwan_mode() {
28+
ETH_WAN_ENABLED=$(syscfg get eth_wan_enabled 2>/dev/null)
29+
if [ "$ETH_WAN_ENABLED" = "true" ]; then
30+
IF_LIST="1 2 3"
31+
else
32+
IF_LIST="1 2 3 4"
33+
fi
34+
log "eth_wan_enabled=$ETH_WAN_ENABLED"
35+
log "Checking interfaces: $IF_LIST"
36+
}
37+
38+
# ---------------------------------------------------------
39+
# Sum AssociatedDeviceNumberOfEntries for all interfaces
40+
# ---------------------------------------------------------
41+
get_dmcli_sum() {
42+
SUM=0
43+
DMCLI_VALUES=""
44+
for IFNUM in $IF_LIST; do
45+
VALUE=$($DMCLI Device.Ethernet.Interface.${IFNUM}.X_RDKCENTRAL-COM_AssociatedDeviceNumberOfEntries \
46+
2>/dev/null | awk '/value:/ {print $NF}')
47+
VALUE=${VALUE:-0}
48+
DMCLI_VALUES="$DMCLI_VALUES IF$IFNUM:$VALUE"
49+
SUM=$((SUM + VALUE))
50+
done
51+
log "DMCLI interface counts:$DMCLI_VALUES"
52+
log "Total associated devices (DMCLI sum): $SUM"
53+
}
54+
55+
# ---------------------------------
56+
# Get eth_api total eth dev count
57+
# ---------------------------------
58+
get_total_eth() {
59+
TOTAL_ETH=$($ETH_API 2>/dev/null | awk '/Total_ETH:/ {print $2}')
60+
TOTAL_ETH=${TOTAL_ETH:-0}
61+
log "Total_ETH from eth_api: $TOTAL_ETH"
62+
}
63+
64+
# -----------------------
65+
# Get CcspEthAgent PID
66+
# -----------------------
67+
get_service_pid() {
68+
PID=$(pidof "$SERVICE")
69+
log "$SERVICE PID: ${PID:-Not running}"
70+
}
71+
72+
# -------------------------------
73+
# Restart eth agent process
74+
# -------------------------------
75+
restart_service() {
76+
log "Restarting $SERVICE..."
77+
systemctl restart "$SERVICE"
78+
79+
if [ $? -eq 0 ]; then
80+
log "$SERVICE restarted successfully"
81+
# Give it a second to settle
82+
sleep 1
83+
get_service_pid
84+
else
85+
log "ERROR: Failed to restart $SERVICE"
86+
fi
87+
}
88+
89+
# ----------------------------------
90+
# Main compare and trigger restart
91+
# ----------------------------------
92+
log "===== EthAgent selfheal check started ====="
93+
94+
get_ethwan_mode
95+
96+
# Capture values before restart
97+
get_dmcli_sum
98+
DMCLI_SUM_BEFORE=$SUM
99+
get_total_eth
100+
TOTAL_ETH_BEFORE=$TOTAL_ETH
101+
get_service_pid
102+
PID_BEFORE=$PID
103+
104+
# Compare counts
105+
if [ "$DMCLI_SUM_BEFORE" -eq 0 ] && [ "$TOTAL_ETH_BEFORE" -ne 0 ]; then
106+
log "Mismatch detected (DMCLI_SUM=$DMCLI_SUM_BEFORE, Total_ETH=$TOTAL_ETH_BEFORE)"
107+
restart_service
108+
109+
log "Sleep 10 secs after restart..."
110+
sleep 10
111+
112+
# Capture values after restart
113+
get_dmcli_sum
114+
DMCLI_SUM_AFTER=$SUM
115+
get_total_eth
116+
TOTAL_ETH_AFTER=$TOTAL_ETH
117+
log "After restart - DMCLI_SUM=$DMCLI_SUM_AFTER, Total_ETH=$TOTAL_ETH_AFTER"
118+
else
119+
log "Counts match. No action required."
120+
fi
121+
122+
log "===== EthAgent selfheal check completed ====="
123+
exit 0
124+

scripts/selfheal_bootup.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,4 +988,28 @@ then
988988
echo_t "pci_enumeration_count:$radio_enum_count" >> $SELFHEALFILE
989989
t2ValNotify "PciEnumeration_split" "$radio_enum_count"
990990
fi
991+
992+
# Tech XB7 => MODEL_NUM=CGM4331COM
993+
# CMX XB7 => MODEL_NUM=TG4482A - not included
994+
# Tech XB8 => MODEL_NUM=CGM4981COM
995+
# Tech XB10 => MODEL_NUM=CGM601TCOM
996+
# Sercomm XB10 => MODEL_NUM=SG417DBCT
997+
998+
if [ "$MODEL_NUM" = "CGM4331COM" ] || [ "$MODEL_NUM" = "CGM4981COM" ] || [ "$MODEL_NUM" = "CGM601TCOM" ] || \
999+
[ "$MODEL_NUM" = "SG417DBCT" ]; then
1000+
1001+
echo_t "RDKB_SELFHEAL: Starting ethagent script..."
1002+
ETHAGENT_SCRIPT="$TAD_PATH/ethagent_associated_dev.sh"
1003+
ETHAGENT_LOG="/rdklogs/logs/EthAgentSelfHeal.log"
1004+
1005+
if [ -f "$ETHAGENT_SCRIPT" ]; then
1006+
echo_t "RDKB_SELFHEAL: Running $ETHAGENT_SCRIPT"
1007+
mkdir -p /rdklogs/logs
1008+
1009+
sh "$ETHAGENT_SCRIPT" >> "$ETHAGENT_LOG" 2>&1
1010+
else
1011+
echo_t "RDKB_SELFHEAL: Script missing or not executable: $ETHAGENT_SCRIPT"
1012+
fi
1013+
fi
1014+
9911015
touch /tmp/selfheal_bootup_completed

0 commit comments

Comments
 (0)