Enanced Auto-healing
This commit is contained in:
+28
-1
@@ -172,6 +172,33 @@ def check_auto_healing(client, status):
|
||||
msg = f"🛠 Auto-healing: {proc_name} offline. Restarting {attempts+1}/3..."
|
||||
client.publish(f"devices/{CLIENT_ID}/logs", msg)
|
||||
send_telegram_message(msg)
|
||||
|
||||
# --- SPECIAL RULE FOR MMDVMHOST ---
|
||||
# If the failed daemon is MMDVMHost, perform a hardware reset of the modem first
|
||||
if proc_name.lower() == "mmdvmhost" and GPIO_AVAILABLE:
|
||||
try:
|
||||
RESET_PIN = 21
|
||||
GPIO.setwarnings(False)
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(RESET_PIN, GPIO.OUT)
|
||||
|
||||
# Send pulse
|
||||
GPIO.output(RESET_PIN, GPIO.LOW)
|
||||
time.sleep(0.5)
|
||||
GPIO.output(RESET_PIN, GPIO.HIGH)
|
||||
GPIO.cleanup(RESET_PIN)
|
||||
|
||||
msg_hw = "🔌 Auto-healing: Hardware HAT Reset sent"
|
||||
print(f"[{CLIENT_ID}] {msg_hw}")
|
||||
client.publish(f"devices/{CLIENT_ID}/logs", msg_hw)
|
||||
|
||||
# Wait for the modem firmware to boot before starting the daemon
|
||||
time.sleep(1.5)
|
||||
except Exception as e:
|
||||
print(f"Auto-healing GPIO Error: {e}")
|
||||
# ----------------------------------
|
||||
|
||||
# Restart the service (whether MMDVMHost or any other)
|
||||
subprocess.run(["sudo", "systemctl", "restart", proc_name])
|
||||
elif attempts == 3:
|
||||
msg = f"🚨 CRITICAL: {proc_name} failed!"
|
||||
@@ -380,7 +407,7 @@ def on_message(client, userdata, msg):
|
||||
def auto_publish_task(client):
|
||||
while True:
|
||||
status = publish_all(client)
|
||||
publish_all_ini_files(client) # <--- HERE IS THE CORRECT LOOP!
|
||||
publish_all_ini_files(client)
|
||||
check_auto_healing(client, status)
|
||||
time.sleep(cfg['settings'].get('update_interval', 30))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user