Add status page quick actions

Co-authored-by: Copilot <[email protected]>
This commit is contained in:
Mathieu Moran
2026-08-10 18:40:22 -04:00
co-authored by Copilot
parent ef38ec92b4
commit 8907c51016
10 changed files with 202 additions and 2 deletions
+48
View File
@@ -1,6 +1,7 @@
import os
import subprocess
import time
from threading import Thread
from urllib.parse import urlparse
import requests
@@ -22,6 +23,14 @@ SERVICE_UNITS = (
("Hotspot watcher", "yaris-netwatch.timer"),
("Phone uplink wait", "yaris-uplink-wait.service"),
)
RESTART_COMMAND = [
"sudo",
"-n",
"/usr/bin/systemctl",
"restart",
"--no-block",
"yaris-obd.service",
]
def parse_systemctl_show(text):
@@ -41,6 +50,45 @@ def parse_systemctl_show(text):
}
def _run_restart_command():
subprocess.run(
RESTART_COMMAND,
capture_output=True,
text=True,
timeout=10,
check=True,
)
def _delayed_restart(delay_seconds):
time.sleep(delay_seconds)
try:
_run_restart_command()
except (OSError, subprocess.SubprocessError) as error:
print(f"Could not restart yaris-obd.service from status page: {error}")
def request_app_restart():
try:
subprocess.run(
["sudo", "-n", "-l", *RESTART_COMMAND[2:]],
capture_output=True,
text=True,
timeout=5,
check=True,
)
except (OSError, subprocess.SubprocessError) as error:
raise RuntimeError(
"Restart permission is not installed on this Pi yet. "
"Run deploy/install_service.sh once to install the status-action sudoers file."
) from error
Thread(target=_delayed_restart, args=(1,), daemon=True).start()
return {
"status": "restart_scheduled",
"message": "App restart requested. The page may disconnect for a few seconds.",
}
def _systemd_unit_status(label, unit):
try:
result = subprocess.run(