37 lines
1 KiB
Python
37 lines
1 KiB
Python
import os
|
|
import importlib.resources
|
|
|
|
from pyinfra.operations import apt, files, pip, server, systemd
|
|
|
|
|
|
# install into .local/lib
|
|
def install(unix_user) -> None:
|
|
remember_package = importlib.resources.files("remember_remember_bot")
|
|
working_directory = os.getcwd()
|
|
remote_venv_dir = f"{working_directory}/venv"
|
|
|
|
# install systemd units
|
|
fn = "remember-remember-bot"
|
|
service_file = remember_package / "pyinfra_assets" / f"{fn}.service.j2"
|
|
files.template(
|
|
name=f"Upload {fn}.service",
|
|
src=service_file,
|
|
dest=f"/home/{unix_user}/.config/systemd/user/{fn}.service",
|
|
execpath=f"{remote_venv_dir}/bin/{fn}",
|
|
working_directory=working_directory,
|
|
unix_user=unix_user,
|
|
)
|
|
systemd.service(
|
|
name=f"Setup {fn} service",
|
|
service=f"{fn}.service",
|
|
running=True,
|
|
enabled=True,
|
|
restarted=True,
|
|
daemon_reload=True,
|
|
user_mode=True,
|
|
)
|
|
|
|
|
|
unix_user = os.environ.get("REMEMBER_PYINFRA_USER", os.environ.get("USER"))
|
|
install(unix_user)
|