enable auto-start at boot

This commit is contained in:
missytake 2024-09-19 14:37:39 +02:00
parent 65192f449e
commit 35a96388b9
Signed by: missytake
GPG key ID: 04CC6658320518DF

View file

@ -5,7 +5,7 @@ from pyinfra.operations import apt, files, pip, server, systemd
# install into .local/lib # install into .local/lib
def install(unix_user) -> None: def install(unix_user, enable_linger=True) -> None:
remember_package = importlib.resources.files("remember_remember_bot") remember_package = importlib.resources.files("remember_remember_bot")
working_directory = os.getcwd() working_directory = os.getcwd()
remote_venv_dir = f"{working_directory}/venv" remote_venv_dir = f"{working_directory}/venv"
@ -13,6 +13,22 @@ def install(unix_user) -> None:
# install systemd units # install systemd units
fn = "remember-remember-bot" fn = "remember-remember-bot"
service_file = remember_package / "pyinfra_assets" / f"{fn}.service.j2" service_file = remember_package / "pyinfra_assets" / f"{fn}.service.j2"
if enable_linger:
server.shell(
name=f"enable {unix_user}'s systemd units to auto-start at boot",
commands=[f"loginctl enable-linger {unix_user}"],
)
files.line(
name=f"{unix_user} .profile: ensure XDG_RUNTIME_DIR",
path=f"/home/{unix_user}/.profile",
line='export XDG_RUNTIME_DIR="/run/user/$UID"',
)
files.line(
name=f"{unix_user} .profile: ensure DBUS_SESSION_BUS_ADDRESS",
path=f"/home/{unix_user}/.profile",
line='export DBUS_SESSION_BUS_ADDRESS="unix:path=${XDG_RUNTIME_DIR}/bus"',
)
files.template( files.template(
name=f"Upload {fn}.service", name=f"Upload {fn}.service",
src=service_file, src=service_file,