Replace GTK4 desktop app with FastAPI web app (Sovran_SystemsOS Hub)
Agent-Logs-Url: https://github.com/naturallaw777/staging_alpha/sessions/5c173acb-776f-4cd2-bc89-bb7675e38677 Co-authored-by: naturallaw777 <99053422+naturallaw777@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
af1ad09e2e
commit
42900608f6
40
app/sovran_systemsos_web/systemctl.py
Normal file
40
app/sovran_systemsos_web/systemctl.py
Normal file
@@ -0,0 +1,40 @@
|
||||
"""Thin wrapper around the systemctl CLI for Sovran_SystemsOS_Hub."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import subprocess
|
||||
from typing import Literal
|
||||
|
||||
|
||||
def _run(cmd: list[str]) -> str:
|
||||
try:
|
||||
result = subprocess.run(cmd, capture_output=True, text=True, timeout=10)
|
||||
return result.stdout.strip()
|
||||
except Exception:
|
||||
return ""
|
||||
|
||||
|
||||
def is_active(unit: str, scope: Literal["system", "user"] = "system") -> str:
|
||||
return _run(["systemctl", f"--{scope}", "is-active", unit]) or "unknown"
|
||||
|
||||
|
||||
def is_enabled(unit: str, scope: Literal["system", "user"] = "system") -> str:
|
||||
return _run(["systemctl", f"--{scope}", "is-enabled", unit]) or "unknown"
|
||||
|
||||
|
||||
def run_action(
|
||||
action: str,
|
||||
unit: str,
|
||||
scope: Literal["system", "user"] = "system",
|
||||
method: str = "systemctl",
|
||||
) -> bool:
|
||||
base_cmd = ["systemctl", f"--{scope}", action, unit]
|
||||
if scope == "system" and method == "pkexec":
|
||||
cmd = ["pkexec", "--user", "root"] + base_cmd
|
||||
else:
|
||||
cmd = base_cmd
|
||||
try:
|
||||
result = subprocess.run(cmd, capture_output=True, text=True, timeout=30)
|
||||
return result.returncode == 0
|
||||
except Exception:
|
||||
return False
|
||||
Reference in New Issue
Block a user