This commit is contained in:
2026-01-23 02:46:16 -08:00
parent 7cf47e26de
commit e8a53afc3d

View File

@@ -366,21 +366,35 @@ def install_service_systemd(
content = f"[Unit]\nDescription=Medios-Macina Client\nAfter=network.target\n\n[Service]\nType=simple\nExecStart={exec_args}\nWorkingDirectory={str(repo_root)}\nRestart=on-failure\nEnvironment=PYTHONUNBUFFERED=1\n\n[Install]\nWantedBy=default.target\n" content = f"[Unit]\nDescription=Medios-Macina Client\nAfter=network.target\n\n[Service]\nType=simple\nExecStart={exec_args}\nWorkingDirectory={str(repo_root)}\nRestart=on-failure\nEnvironment=PYTHONUNBUFFERED=1\n\n[Install]\nWantedBy=default.target\n"
unit_file.write_text(content, encoding="utf-8") unit_file.write_text(content, encoding="utf-8")
subprocess.run([systemctl, "--user", "daemon-reload"], check=True) def _run_systemctl(cmd: List[str]) -> subprocess.CompletedProcess:
subprocess.run( try:
return subprocess.run(
cmd,
capture_output=True,
text=True,
check=False,
)
except Exception as exc:
raise
failed = False
for cmd in [
[systemctl, "--user", "daemon-reload"],
[systemctl, [systemctl,
"--user", "--user",
"enable", "enable",
"--now", "--now",
f"{service_name}.service"], f"{service_name}.service"],
check=True ]:
) result = _run_systemctl(cmd)
print(f"systemd user service '{service_name}' installed and started.") if result.returncode != 0:
return True stderr = (result.stderr or "").strip()
except subprocess.CalledProcessError as e: stdout = (result.stdout or "").strip()
err_msg = str(e) err_lines = "\n".join([l for l in [stderr, stdout] if l])
print("Failed to create systemd user service:", err_msg) print("Failed to run systemctl", cmd, "exit", result.returncode)
if "user scope bus" in err_msg.lower(): if err_lines:
print(err_lines)
if "user scope bus" in err_lines.lower() or "xdg_runtime_dir" in err_lines.lower():
print("systemd user bus unavailable; falling back to cron @reboot install.") print("systemd user bus unavailable; falling back to cron @reboot install.")
return install_service_cron( return install_service_cron(
service_name, service_name,
@@ -391,7 +405,14 @@ def install_service_systemd(
pull=pull, pull=pull,
workspace_root=workspace_root, workspace_root=workspace_root,
) )
failed = True
break
if failed:
return False return False
print(f"systemd user service '{service_name}' installed and started.")
return True
except Exception as exc: except Exception as exc:
print("systemd install error:", exc) print("systemd install error:", exc)
return False return False