liab-deployments/liab_deployments/operations/user.py
Michael Hanke b9a3d8193d
rf: remove uv help
There is now the more functional `deploy_uv`.

The only user of this removed helper is the dumpthings deployment, which
is changing in the next commit.
2026-09-30 13:08:35 +02:00

52 lines
1.2 KiB
Python

from pyinfra import host
from pyinfra.api import (
FactBase,
operation,
)
from pyinfra.operations import (
server,
)
class SystemdUserLinger(FactBase):
"""Whether `loginctl` reports user lingering to be enabled."""
def requires_command(self, **kwargs) -> str:
return 'loginctl'
def command(self, user: str):
return (
f'loginctl show-user "{user}" -p Linger --value || echo FAILED'
)
def process(self, lines):
if not lines:
return None
return lines[0].strip() == 'yes'
@operation()
def systemd_service(
user_name,
user_id,
user_home,
):
"""Set up a user for running systemd services in user-space"""
yield from server.user._inner(
user=user_name,
uid=user_id,
home=user_home,
present=True,
shell='/usr/sbin/nologin',
# prevent password-based login
password='!',
# TODO support additional group membership
#groups=['systemd-journal'],
)
if not host.get_fact(SystemdUserLinger, user_name):
yield from server.shell._inner(
commands=[
f'loginctl enable-linger {user_name}',
],
)