Files
reyna-cli/backup/macmini-automation-baseline-2026-08-03/hermes-scripts/restart_gw.py
T
2026-08-03 11:47:09 -04:00

23 lines
900 B
Python

#!/usr/bin/env python3
import subprocess, time, os, sys
# Unset gateway marker for child systemctl calls to avoid any inner guard (though systemctl itself doesn't check)
env = os.environ.copy()
env.pop("_HERMES_GATEWAY", None)
def run_systemctl(unit, action="restart"):
print(f"Running: systemctl --user {action} {unit}", flush=True)
proc = subprocess.run(["/usr/bin/systemctl", "--user", action, unit], env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, timeout=30)
print(f"exit={proc.returncode} out={proc.stdout[:500]} err={proc.stderr[:500]}", flush=True)
return proc.returncode
# restart kids first
rc1 = run_systemctl("hermes-gateway-kids", "restart")
print(f"kids restart rc={rc1}", flush=True)
time.sleep(3.5)
rc2 = run_systemctl("hermes-gateway", "restart")
print(f"default restart rc={rc2}", flush=True)
time.sleep(6)
print("Done restarts", flush=True)