ui: make ControlGroup query robust; drop legacy instruction files
This commit is contained in:
@@ -928,19 +928,54 @@ RU: Применяет policy-rules и проверяет health. При оши
|
||||
if p.returncode != 0:
|
||||
raise RuntimeError(f"systemd-run failed: {p.returncode}\n{out}".strip())
|
||||
|
||||
p2 = subprocess.run(
|
||||
["systemctl", "--user", "show", "-p", "ControlGroup", "--value", unit],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=False,
|
||||
)
|
||||
out2 = ((p2.stdout or "") + (p2.stderr or "")).strip()
|
||||
cg = (p2.stdout or "").strip()
|
||||
if p2.returncode != 0 or not cg:
|
||||
raise RuntimeError(f"failed to query ControlGroup\n{out2}".strip())
|
||||
# EN: Some apps (e.g. Chrome wrappers) can return quickly; the transient scope
|
||||
# EN: may appear/disappear fast. Retry briefly to avoid race.
|
||||
# RU: Некоторые приложения (например, chrome-wrapper) быстро завершаются; scope
|
||||
# RU: может появиться/исчезнуть очень быстро. Делаем небольшой retry.
|
||||
cg = self._control_group_for_unit_retry(unit, timeout_sec=2.0)
|
||||
|
||||
return cg, out
|
||||
|
||||
def _control_group_for_unit_retry(self, unit: str, *, timeout_sec: float = 2.0) -> str:
|
||||
u = (unit or "").strip()
|
||||
if not u:
|
||||
raise ValueError("empty unit")
|
||||
|
||||
deadline = time.time() + max(0.2, float(timeout_sec or 0))
|
||||
last_out = ""
|
||||
while time.time() < deadline:
|
||||
code, out = self._systemctl_user(["show", "-p", "ControlGroup", "--value", u])
|
||||
last_out = out or ""
|
||||
if code == 0:
|
||||
cg = (out or "").strip()
|
||||
if cg:
|
||||
return cg
|
||||
low = (out or "").lower()
|
||||
if "could not be found" in low or "not found" in low or "loaded units listed" in low:
|
||||
break
|
||||
time.sleep(0.1)
|
||||
|
||||
# Provide a more actionable error for users.
|
||||
code_s, out_s = self._systemctl_user(["status", u, "--no-pager", "--plain"])
|
||||
status_txt = (out_s or "").strip()
|
||||
hint = (
|
||||
"EN: Scope unit may have exited immediately. If the app is already running, "
|
||||
"this launch may not create a new process tree inside the scope.\n"
|
||||
"EN: Try closing the app полностью and запуск again from here.\n"
|
||||
"RU: Scope мог завершиться сразу. Если приложение уже запущено, повторный запуск "
|
||||
"может не создать новый процесс внутри scope.\n"
|
||||
"RU: Попробуй полностью закрыть приложение и запустить снова отсюда."
|
||||
)
|
||||
raise RuntimeError(
|
||||
(
|
||||
"failed to query ControlGroup\n"
|
||||
+ (last_out.strip() or "(no output)")
|
||||
+ ("\n\nstatus:\n" + status_txt if status_txt else "")
|
||||
+ "\n\n"
|
||||
+ hint
|
||||
).strip()
|
||||
)
|
||||
|
||||
def on_app_run(self) -> None:
|
||||
def work() -> None:
|
||||
cmdline = (self.ed_app_cmd.text() or "").strip()
|
||||
|
||||
Reference in New Issue
Block a user