Guide full-service installs and report installer progress

This commit is contained in:
parkel committed 2026-11-22 21:27:29 +01:00
1 parent e68e54288f
commit 23adbe7b2d
4 files changed
+327 -81

No files matched your search

+75 -36
View File
@@ -10,9 +10,10 @@ import subprocess
import sys
import time
import tomllib
from contextlib import contextmanager
from contextlib import contextmanager, nullcontext
from pathlib import Path
from tempfile import TemporaryDirectory
from threading import Event, Thread
from . import certificates, roles
from .config import REMOTE_MODES, InstallError, platform_settings
@@ -198,7 +199,7 @@ def systemctl(*args):
)
def install_packages(packages, *, mail_host=""):
def install_packages(packages, *, mail_host="", step=nullcontext):
status = subprocess.run(
["dpkg-query", "-W", "-f=${db:Status-Status} ${Package}\n", *packages],
stdin=subprocess.DEVNULL,
@@ -224,26 +225,28 @@ def install_packages(packages, *, mail_host=""):
source=answers.encode(),
label="Choose the local Postfix installation profile",
)
run(
"apt-get",
"update",
label="Refresh the configured APT repositories",
env=apt_env,
timeout=600,
)
run(
"apt-get",
"install",
"--yes",
"--no-upgrade",
*packages,
label="Install the required APT packages",
env=apt_env,
timeout=1800,
)
with step("Refreshing APT repositories"):
run(
"apt-get",
"update",
label="Refresh the configured APT repositories",
env=apt_env,
timeout=600,
)
with step("Installing system packages"):
run(
"apt-get",
"install",
"--yes",
"--no-upgrade",
*packages,
label="Install the required APT packages",
env=apt_env,
timeout=1800,
)
def install_release(release):
def install_release(release, *, step=nullcontext):
root_directory(VENV.parent)
if os.path.lexists(VENV):
root_directory(VENV)
@@ -276,15 +279,16 @@ def install_release(release):
for key in ("PIP_NO_INDEX", "PIP_FIND_LINKS")
if key in os.environ
}
run(
BINDIR / "pip",
"install",
"--disable-pip-version-check",
with_extras,
label="Install Coulobre and its Python dependencies",
env=pip_env,
timeout=1200,
)
with step("Installing Coulobre and its Python dependencies"):
run(
BINDIR / "pip",
"install",
"--disable-pip-version-check",
with_extras,
label="Install Coulobre and its Python dependencies",
env=pip_env,
timeout=1200,
)
@contextmanager
@@ -308,15 +312,45 @@ def install_lock():
class Installer:
def __init__(self, plan, password, progress):
def __init__(self, plan, password, progress, *, heartbeat=False):
self.plan = plan
self.password = password
self.progress = progress
self.heartbeat = heartbeat
self.state_file = STATE / "installation.json"
self.php, self.modern_mail = platform_settings()
with (SOURCE / "pyproject.toml").open("rb") as project:
self.release = tomllib.load(project)["project"]["version"]
@contextmanager
def step(self, label):
started = time.monotonic()
finished = Event()
self.progress(f"{label}.")
def report_elapsed():
while not finished.wait(15):
elapsed = int(time.monotonic() - started)
self.progress(f"{label}… {elapsed}s elapsed.")
thread = Thread(target=report_elapsed) if self.heartbeat else None
if thread is not None:
thread.start()
try:
yield
except (InstallError, OSError, ValueError):
self.progress(
f"{label} failed after {int(time.monotonic() - started)}s."
)
raise
finally:
finished.set()
if thread is not None:
thread.join()
self.progress(
f"{label} completed in {int(time.monotonic() - started)}s."
)
def save_state(self):
put_file(
self.state_file,
@@ -421,10 +455,13 @@ class Installer:
"Environment=RABBITMQ_CONFIG_FILE=/etc/coulobre-rabbitmq.conf\n",
)
systemctl("daemon-reload")
systemctl(
"enable", "--now", "mariadb.service", "rabbitmq-server.service"
)
systemctl("restart", "mariadb.service", "rabbitmq-server.service")
for name, unit in (
("MariaDB", "mariadb.service"),
("RabbitMQ", "rabbitmq-server.service"),
):
with self.step(f"Starting {name} on loopback"):
systemctl("enable", "--now", unit)
systemctl("restart", unit)
def mariadb(sql):
return run(
@@ -679,11 +716,13 @@ class Installer:
install_packages(
self.packages(),
mail_host=mail.host if mail.mode == "local" else "",
step=self.step,
)
install_release(self.release)
install_release(self.release, step=self.step)
self.install_certificates()
self.progress("Preparing MariaDB and RabbitMQ on loopback.")
self.configure_stores()
with self.step("Configuring database and message broker access"):
self.configure_stores()
self.progress(
"Configuring hosting service identities and provisioning."
)