MCPcopy Create free account
hub / github.com/Coooolfan/onlyboxes / install_systemd_service

Function install_systemd_service

scripts/install.py:503–523  ·  view source on GitHub ↗
(service_name: str, unit_content: str)

Source from the content-addressed store, hash-verified

501
502
503def 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
526def generate_console_binary_unit(workdir: Path, hash_key: str, admin_password: str,

Callers 1

mainFunction · 0.85

Calls 3

infoFunction · 0.85
run_cmdFunction · 0.85
fatalFunction · 0.70

Tested by

no test coverage detected