mirror of
https://github.com/MarekWo/mc-webui.git
synced 2026-03-28 17:42:45 +01:00
feat(watchdog): skip USB reset if TCP connection is used
Since mc-webui can now connect via TCP to a remote proxy instead of local USB/serial device, the hardware USB bus reset logic in Watchdog will no longer blindly attempt a reset on repeated container crashes. Added \is_tcp_connection()\ helper to read the config and conditionally skip the USB reset if TCP is active.
This commit is contained in:
@@ -136,6 +136,23 @@ def auto_detect_usb_device() -> str:
|
||||
log(f"Error during USB device auto-detection: {e}", "ERROR")
|
||||
return None
|
||||
|
||||
def is_tcp_connection() -> bool:
|
||||
"""Check if the application is configured to use a TCP connection instead of a serial port."""
|
||||
env_file = os.path.join(MCWEBUI_DIR, '.env')
|
||||
|
||||
if os.path.exists(env_file):
|
||||
try:
|
||||
with open(env_file, 'r') as f:
|
||||
for line in f:
|
||||
if line.startswith('MC_TCP_HOST='):
|
||||
val = line.split('=', 1)[1].strip().strip('"\'')
|
||||
if val:
|
||||
return True
|
||||
except Exception as e:
|
||||
log(f"Failed to read .env file for TCP host: {e}", "WARN")
|
||||
|
||||
return False
|
||||
|
||||
def reset_esp32_device():
|
||||
"""Perform a hardware reset on ESP32/LoRa device using DTR/RTS lines via ioctl."""
|
||||
serial_port = auto_detect_serial_port()
|
||||
@@ -416,7 +433,7 @@ def handle_unhealthy_container(container_name: str, status: dict):
|
||||
restart_success = False
|
||||
if container_name == 'mc-webui':
|
||||
recent_restarts = count_recent_restarts(container_name, minutes=8)
|
||||
if recent_restarts >= 3:
|
||||
if recent_restarts >= 3 and not is_tcp_connection():
|
||||
log(f"{container_name} has been restarted {recent_restarts} times in the last 8 minutes. Attempting hardware USB reset.", "WARN")
|
||||
# Stop the container first so it releases the serial port
|
||||
run_compose_command(['stop', container_name])
|
||||
@@ -425,6 +442,8 @@ def handle_unhealthy_container(container_name: str, status: dict):
|
||||
time.sleep(5) # Give OS time to re-enumerate the device
|
||||
restart_success = start_container(container_name)
|
||||
else:
|
||||
if recent_restarts >= 3 and is_tcp_connection():
|
||||
log(f"{container_name} has been restarted {recent_restarts} times in the last 8 minutes. TCP connection used, skipping hardware USB reset.", "WARN")
|
||||
restart_success = restart_container(container_name)
|
||||
else:
|
||||
# Restart the container
|
||||
@@ -493,7 +512,7 @@ def handle_unresponsive_device(container_name: str, status: dict):
|
||||
restart_success = False
|
||||
if container_name == 'mc-webui':
|
||||
recent_restarts = count_recent_restarts(container_name, minutes=8)
|
||||
if recent_restarts >= 3:
|
||||
if recent_restarts >= 3 and not is_tcp_connection():
|
||||
log(f"{container_name} has been restarted {recent_restarts} times in the last 8 minutes. Attempting hardware USB reset.", "WARN")
|
||||
# Stop the container first so it releases the serial port
|
||||
run_compose_command(['stop', container_name])
|
||||
@@ -502,6 +521,8 @@ def handle_unresponsive_device(container_name: str, status: dict):
|
||||
time.sleep(5) # Give OS time to re-enumerate the device
|
||||
restart_success = start_container(container_name)
|
||||
else:
|
||||
if recent_restarts >= 3 and is_tcp_connection():
|
||||
log(f"{container_name} has been restarted {recent_restarts} times in the last 8 minutes. TCP connection used, skipping hardware USB reset.", "WARN")
|
||||
restart_success = restart_container(container_name)
|
||||
else:
|
||||
# Restart the container
|
||||
|
||||
Reference in New Issue
Block a user