31 lines
948 B
Python
31 lines
948 B
Python
from importlib import resources
|
|
from pathlib import Path
|
|
from typing import Callable
|
|
|
|
from l4d2host.process import run_command
|
|
|
|
|
|
def ensure_template_unit(target_dir: Path | None = None) -> Path:
|
|
if target_dir is None:
|
|
target_dir = Path.home() / ".config/systemd/user"
|
|
target_dir.mkdir(parents=True, exist_ok=True)
|
|
target_file = target_dir / "l4d2@.service"
|
|
body = resources.files("l4d2host.templates").joinpath("l4d2@.service").read_text()
|
|
target_file.write_text(body)
|
|
return target_file
|
|
|
|
|
|
def daemon_reload(
|
|
*,
|
|
on_stdout: Callable[[str], None] | None = None,
|
|
on_stderr: Callable[[str], None] | None = None,
|
|
passthrough: bool = False,
|
|
should_cancel: Callable[[], bool] | None = None,
|
|
) -> None:
|
|
run_command(
|
|
["systemctl", "--user", "daemon-reload"],
|
|
on_stdout=on_stdout,
|
|
on_stderr=on_stderr,
|
|
passthrough=passthrough,
|
|
should_cancel=should_cancel,
|
|
)
|