You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决libqmi与networkd-dispatcher初始化LTE模块时脚本重复执行的问题

Fixing Repeated Execution of Your WWAN Initialization Script with networkd-dispatcher

Let’s break down why your script keeps running over and over, and walk through concrete fixes to stabilize your system:

The Root Cause

Your script lives in /etc/networkd-dispatcher/degraded.d/—this directory triggers scripts every time the network enters a degraded state. The problem? Your script’s actions (like toggling the interface up/down or modifying QMI settings) are probably causing the network state to flip between degraded and other states, creating an endless loop. Adding sleep 10 doesn’t fix this because it doesn’t address why the state is changing repeatedly.


1. Move the Script to a Better Directory

Instead of reacting to degraded states, run the script only when the WWAN interface first comes online. Use one of these networkd-dispatcher directories instead:

  • up.d: Triggers when the interface transitions to the "up" state
  • post-up.d: Triggers after the interface is fully up and configured

This way, your script runs once when the interface starts, not every time the network hits a blip.

2. Add a Lock File to Block Re-Runs

Even with the right directory, a lock file ensures the script never runs multiple times at once or in quick succession. Update your script with this logic:

#!/bin/bash

# Create a lock file to prevent duplicate runs
LOCK_FILE="/var/run/wwan_init.lock"
if [ -f "$LOCK_FILE" ]; then
    echo "WWAN setup already in progress or done—exiting."
    exit 0
fi
touch "$LOCK_FILE"
trap 'rm -f "$LOCK_FILE"' EXIT  # Clean up lock when the script finishes

interface="${IFACE}"
if [[ "$interface" == *"wwan"* ]]; then
    device="/dev/cdc-wdm${interface: -1}"
    is_wwan="y"
fi

if [[ "$is_wwan" == "y" ]]; then
    # Only make changes if they're needed
    # Check if raw_ip is already enabled
    if [ "$(cat "/sys/class/net/${interface}/qmi/raw_ip")" != "Y" ]; then
        echo "Y" > "/sys/class/net/${interface}/qmi/raw_ip"
    fi

    # Check if autoconnect is already enabled
    if ! qmicli -p -d "${device}" --wds-get-autoconnect-settings | grep -q "enabled"; then
        ip link set dev "${interface}" down
        qmi-network "${device}" start || true
        qmicli -p -d "${device}" --wds-set-autoconnect-settings=enabled || true
        ip link set dev "${interface}" up
    fi
fi

3. Cut Out Unnecessary Interface Toggles

Your original script brings the interface down/up every time it runs, which is a big trigger for repeated state changes. By adding checks (like verifying raw_ip and autoconnect status first), you only modify the interface when it’s actually needed—no more unnecessary state flips.

4. Check for Conflicting Scripts

Make sure no other networkd-dispatcher scripts are messing with your WWAN interface. Run this to list all active scripts:

ls -la /etc/networkd-dispatcher/

Look for any scripts in other directories (like down.d or dormant.d) that might be modifying the WWAN interface and causing state loops.


内容的提问来源于stack exchange,提问作者Florian Berndl

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 22:57:28