pyinfra deploy.py to deploy a local bot user unit
This commit is contained in:
parent
7711c106b7
commit
0dcec5dce2
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
||||||
*.swp
|
*.swp
|
||||||
|
.env
|
||||||
*.egg-info/
|
*.egg-info/
|
||||||
__pycache__/
|
__pycache__/
|
||||||
/.tox/
|
/.tox/
|
||||||
|
|
36
local-deploy.py
Normal file
36
local-deploy.py
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
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)
|
|
@ -0,0 +1,12 @@
|
||||||
|
[Unit]
|
||||||
|
Description=run deltachat remember-remember-bot
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart={{ execpath }} --debug
|
||||||
|
EnvironmentFile={{ working_directory }}/.env
|
||||||
|
WorkingDirectory={{ working_directory }}
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=5s
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
Loading…
Reference in a new issue