forked from lab-in-a-box/liab-deployments
58 lines
1.3 KiB
Python
58 lines
1.3 KiB
Python
from pyinfra.operations import (
|
|
files,
|
|
server,
|
|
)
|
|
|
|
|
|
def systemd_service(
|
|
user_name,
|
|
user_id,
|
|
user_home,
|
|
):
|
|
"""Set up a user for running systemd services in user-space"""
|
|
server.user(
|
|
name=f'Ensure user {user_name}({user_id})',
|
|
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'],
|
|
)
|
|
|
|
server.shell(
|
|
name=f'Enable user {user_name!r} lingering',
|
|
commands=[
|
|
f'loginctl enable-linger {user_name}',
|
|
],
|
|
)
|
|
|
|
files.directory(
|
|
name=f'Ensure user {user_name!r} service unit directory',
|
|
path=f'{user_home}/.config/systemd/user',
|
|
present=True,
|
|
_sudo_user=user_name,
|
|
)
|
|
|
|
files.directory(
|
|
name=f'Ensure user {user_name!r} container unit directory',
|
|
path=f'{user_home}/.config/containers/systemd',
|
|
present=True,
|
|
_sudo_user=user_name,
|
|
)
|
|
|
|
|
|
def uv(
|
|
user_name,
|
|
# TODO uv version
|
|
):
|
|
server.shell(
|
|
name='Ensure `uv` availability',
|
|
commands=[
|
|
'which -s uv || curl -LsSf https://astral.sh/uv/install.sh | sh',
|
|
],
|
|
_sudo_user=user_name,
|
|
)
|