| 501 | |
| 502 | |
| 503 | def install_systemd_service(service_name: str, unit_content: str) -> None: |
| 504 | service_path = Path(f"/etc/systemd/system/{service_name}.service") |
| 505 | try: |
| 506 | service_path.write_text(unit_content) |
| 507 | except PermissionError: |
| 508 | fatal("systemd", f"Permission denied writing {service_path}. Run as root or with sudo.") |
| 509 | |
| 510 | info(f"Service file written to {service_path}") |
| 511 | |
| 512 | run_cmd(["systemctl", "daemon-reload"]) |
| 513 | info("daemon-reload done.") |
| 514 | |
| 515 | result = run_cmd(["systemctl", "enable", "--now", service_name], check=False) |
| 516 | if result.returncode != 0: |
| 517 | fatal( |
| 518 | "systemd", |
| 519 | f"Failed to enable/start {service_name}:\n{result.stderr.strip()}\n" |
| 520 | f" Check: journalctl -u {service_name} -n 200 --no-pager", |
| 521 | ) |
| 522 | |
| 523 | info(f"Service {service_name} enabled and started.") |
| 524 | |
| 525 | |
| 526 | def generate_console_binary_unit(workdir: Path, hash_key: str, admin_password: str, |