2026-11-22 16:39:27 +01:00
|
|
|
import fcntl
|
|
|
|
|
import grp
|
|
|
|
|
import json
|
|
|
|
|
import os
|
|
|
|
|
import pwd
|
|
|
|
|
import secrets
|
2026-11-22 21:43:37 +01:00
|
|
|
import smtplib
|
2026-11-22 16:39:27 +01:00
|
|
|
import socket
|
|
|
|
|
import stat
|
|
|
|
|
import subprocess
|
|
|
|
|
import sys
|
|
|
|
|
import time
|
|
|
|
|
import tomllib
|
2026-11-22 21:27:29 +01:00
|
|
|
from contextlib import contextmanager, nullcontext
|
2026-11-22 16:39:27 +01:00
|
|
|
from pathlib import Path
|
|
|
|
|
from tempfile import TemporaryDirectory
|
2026-11-22 21:27:29 +01:00
|
|
|
from threading import Event, Thread
|
2026-11-22 16:39:27 +01:00
|
|
|
|
2026-11-22 17:51:05 +01:00
|
|
|
from . import certificates, roles
|
|
|
|
|
from .config import REMOTE_MODES, InstallError, platform_settings
|
2026-11-22 16:39:27 +01:00
|
|
|
|
|
|
|
|
SOURCE = Path(__file__).resolve().parents[2]
|
|
|
|
|
ASSETS = SOURCE / "deploy"
|
|
|
|
|
VENV = Path("/opt/coulobre")
|
|
|
|
|
BINDIR = VENV / "bin"
|
|
|
|
|
ETC = Path("/etc/coulobre")
|
|
|
|
|
ENV_FILE = ETC / "panel.env"
|
|
|
|
|
STATE = Path("/var/lib/coulobre-installer")
|
|
|
|
|
SYSTEMD = Path("/etc/systemd/system")
|
|
|
|
|
STATIC = Path("/var/www/coulobre-panel-static")
|
|
|
|
|
PATH = "/usr/sbin:/usr/bin:/sbin:/bin"
|
|
|
|
|
PANEL_UNITS = (
|
|
|
|
|
"coulobre-panel.service",
|
|
|
|
|
"coulobre-worker.service",
|
|
|
|
|
"coulobre-beat.service",
|
|
|
|
|
)
|
2026-11-22 22:27:08 +01:00
|
|
|
HEALTH_TIMER = "coulobre-health.timer"
|
2026-11-22 16:39:27 +01:00
|
|
|
BASE_PACKAGES = (
|
|
|
|
|
"apache2",
|
|
|
|
|
"mariadb-server",
|
|
|
|
|
"rabbitmq-server",
|
|
|
|
|
"python3-venv",
|
|
|
|
|
"python3-dev",
|
|
|
|
|
"build-essential",
|
|
|
|
|
"pkg-config",
|
|
|
|
|
"default-libmysqlclient-dev",
|
|
|
|
|
"ca-certificates",
|
|
|
|
|
)
|
|
|
|
|
ADMIN_SCRIPT = """import json
|
|
|
|
|
import sys
|
|
|
|
|
import django
|
|
|
|
|
django.setup()
|
|
|
|
|
from django.contrib.auth import get_user_model
|
|
|
|
|
from django.contrib.auth.password_validation import validate_password
|
|
|
|
|
from django.db import transaction
|
|
|
|
|
|
|
|
|
|
data = json.load(sys.stdin)
|
|
|
|
|
users = get_user_model().objects
|
|
|
|
|
with transaction.atomic():
|
|
|
|
|
previous = users.filter(username=data["username"]).first()
|
|
|
|
|
if previous is not None:
|
|
|
|
|
if not previous.is_superuser or previous.email != data["email"]:
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
else:
|
|
|
|
|
validate_password(data["password"])
|
|
|
|
|
users.create_superuser(**data)
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
2026-11-26 22:50:40 +01:00
|
|
|
def run(*args, label, source=None, timeout=120, env=None, failure=None):
|
2026-11-22 16:39:27 +01:00
|
|
|
try:
|
|
|
|
|
result = subprocess.run(
|
|
|
|
|
[os.fspath(value) for value in args],
|
|
|
|
|
input=source,
|
|
|
|
|
stdin=subprocess.DEVNULL if source is None else None,
|
|
|
|
|
capture_output=True,
|
|
|
|
|
env={"PATH": PATH, "LC_ALL": "C.UTF-8", **(env or {})},
|
|
|
|
|
check=False,
|
|
|
|
|
timeout=timeout,
|
|
|
|
|
)
|
|
|
|
|
except (OSError, subprocess.TimeoutExpired):
|
|
|
|
|
raise InstallError(f"{label} failed or timed out.") from None
|
|
|
|
|
if result.returncode:
|
2026-11-26 22:50:40 +01:00
|
|
|
if failure:
|
|
|
|
|
raise InstallError(failure(result.returncode, result.stderr))
|
2026-11-22 16:39:27 +01:00
|
|
|
raise InstallError(f"{label} failed. Check the service and retry.")
|
|
|
|
|
return result.stdout.decode("utf-8", errors="replace")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def root_directory(path, mode=0o755):
|
|
|
|
|
if not os.path.lexists(path):
|
|
|
|
|
path.mkdir(mode=mode)
|
|
|
|
|
info = path.lstat()
|
|
|
|
|
if (
|
|
|
|
|
not stat.S_ISDIR(info.st_mode)
|
|
|
|
|
or info.st_uid != 0
|
|
|
|
|
or info.st_mode & 0o022
|
|
|
|
|
):
|
|
|
|
|
raise InstallError(f"Expected a root-controlled directory at {path}.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def root_file(path, mode):
|
|
|
|
|
info = path.lstat()
|
|
|
|
|
if (
|
|
|
|
|
not stat.S_ISREG(info.st_mode)
|
|
|
|
|
or info.st_uid != 0
|
|
|
|
|
or stat.S_IMODE(info.st_mode) != mode
|
|
|
|
|
):
|
|
|
|
|
raise InstallError(f"Expected a root-owned {mode:04o} file at {path}.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def put_file(path, content, *, mode=0o644, group=0, update=False):
|
|
|
|
|
root_directory(path.parent)
|
|
|
|
|
if os.path.lexists(path):
|
|
|
|
|
root_file(path, mode)
|
|
|
|
|
if path.stat().st_gid != group:
|
|
|
|
|
raise InstallError(f"Check the group ownership of {path}.")
|
|
|
|
|
if path.read_text(encoding="utf-8") == content:
|
|
|
|
|
return
|
|
|
|
|
if not update:
|
|
|
|
|
raise InstallError(f"Existing configuration differs at {path}.")
|
|
|
|
|
with TemporaryDirectory(dir=path.parent) as directory:
|
|
|
|
|
staged = Path(directory) / "new"
|
|
|
|
|
with staged.open("x", encoding="utf-8") as stream:
|
|
|
|
|
stream.write(content)
|
|
|
|
|
stream.flush()
|
|
|
|
|
os.fchown(stream.fileno(), 0, group)
|
|
|
|
|
os.fchmod(stream.fileno(), mode)
|
|
|
|
|
os.fsync(stream.fileno())
|
|
|
|
|
if update:
|
|
|
|
|
staged.replace(path)
|
|
|
|
|
else:
|
|
|
|
|
os.link(staged, path)
|
|
|
|
|
directory_fd = os.open(path.parent, os.O_RDONLY | os.O_DIRECTORY)
|
|
|
|
|
try:
|
|
|
|
|
os.fsync(directory_fd)
|
|
|
|
|
finally:
|
|
|
|
|
os.close(directory_fd)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def group(name):
|
|
|
|
|
try:
|
|
|
|
|
return grp.getgrnam(name)
|
|
|
|
|
except KeyError:
|
|
|
|
|
run("groupadd", "--system", name, label=f"Create group {name}")
|
|
|
|
|
return grp.getgrnam(name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def identity(name, home="/nonexistent"):
|
|
|
|
|
try:
|
|
|
|
|
account = pwd.getpwnam(name)
|
|
|
|
|
except KeyError:
|
2026-11-23 23:41:31 +01:00
|
|
|
private_group = group(name)
|
2026-11-22 16:39:27 +01:00
|
|
|
run(
|
|
|
|
|
"useradd",
|
|
|
|
|
"--system",
|
2026-11-23 23:41:31 +01:00
|
|
|
"--gid",
|
|
|
|
|
str(private_group.gr_gid),
|
2026-11-22 16:39:27 +01:00
|
|
|
"--no-create-home",
|
|
|
|
|
"--home-dir",
|
|
|
|
|
home,
|
|
|
|
|
"--shell",
|
|
|
|
|
"/usr/sbin/nologin",
|
|
|
|
|
name,
|
|
|
|
|
label=f"Create service user {name}",
|
|
|
|
|
)
|
|
|
|
|
account = pwd.getpwnam(name)
|
|
|
|
|
try:
|
|
|
|
|
primary_gid = grp.getgrnam(name).gr_gid
|
|
|
|
|
except KeyError:
|
|
|
|
|
raise InstallError(f"Create a private group for {name}.") from None
|
|
|
|
|
if (
|
|
|
|
|
account.pw_uid == 0
|
|
|
|
|
or account.pw_gid != primary_gid
|
|
|
|
|
or account.pw_dir != home
|
|
|
|
|
or account.pw_shell != "/usr/sbin/nologin"
|
|
|
|
|
or set(os.getgrouplist(name, account.pw_gid)) != {account.pw_gid}
|
|
|
|
|
):
|
|
|
|
|
raise InstallError(f"Review the existing service account {name}.")
|
|
|
|
|
return account
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def install_unit(unit):
|
|
|
|
|
source = ASSETS / "systemd" / unit
|
|
|
|
|
if "/" in unit:
|
|
|
|
|
root_directory((SYSTEMD / unit).parent)
|
|
|
|
|
put_file(SYSTEMD / unit, source.read_text(encoding="utf-8"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def install_worker(group_name, user, socket_unit, worker_unit):
|
|
|
|
|
identity(user)
|
2026-11-23 23:41:31 +01:00
|
|
|
if group_name != user:
|
|
|
|
|
group(group_name)
|
2026-11-22 16:39:27 +01:00
|
|
|
for unit in (
|
|
|
|
|
f"{socket_unit}.socket",
|
|
|
|
|
f"{socket_unit}@.service",
|
|
|
|
|
worker_unit,
|
|
|
|
|
):
|
|
|
|
|
install_unit(unit)
|
|
|
|
|
return worker_unit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def systemctl(*args):
|
|
|
|
|
return run(
|
|
|
|
|
"systemctl", *args, label=f"systemctl {' '.join(args)}", timeout=180
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2026-11-22 21:27:29 +01:00
|
|
|
def install_packages(packages, *, mail_host="", step=nullcontext):
|
2026-11-22 16:39:27 +01:00
|
|
|
status = subprocess.run(
|
|
|
|
|
["dpkg-query", "-W", "-f=${db:Status-Status} ${Package}\n", *packages],
|
|
|
|
|
stdin=subprocess.DEVNULL,
|
|
|
|
|
capture_output=True,
|
|
|
|
|
env={"PATH": PATH},
|
|
|
|
|
timeout=30,
|
|
|
|
|
check=False,
|
|
|
|
|
)
|
|
|
|
|
installed = {
|
|
|
|
|
line.split()[1]
|
|
|
|
|
for line in status.stdout.decode().splitlines()
|
|
|
|
|
if line.startswith("installed ")
|
|
|
|
|
}
|
|
|
|
|
if set(packages) - installed:
|
|
|
|
|
apt_env = {"DEBIAN_FRONTEND": "noninteractive"}
|
|
|
|
|
if mail_host and "postfix" not in installed:
|
|
|
|
|
answers = (
|
|
|
|
|
"postfix postfix/main_mailer_type select Internet Site\n"
|
|
|
|
|
f"postfix postfix/mailname string {mail_host}\n"
|
|
|
|
|
)
|
|
|
|
|
run(
|
|
|
|
|
"debconf-set-selections",
|
|
|
|
|
source=answers.encode(),
|
|
|
|
|
label="Choose the local Postfix installation profile",
|
|
|
|
|
)
|
2026-11-22 21:27:29 +01:00
|
|
|
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,
|
|
|
|
|
)
|
2026-11-22 16:39:27 +01:00
|
|
|
|
|
|
|
|
|
2026-11-22 21:27:29 +01:00
|
|
|
def install_release(release, *, step=nullcontext):
|
2026-11-22 16:39:27 +01:00
|
|
|
root_directory(VENV.parent)
|
|
|
|
|
if os.path.lexists(VENV):
|
|
|
|
|
root_directory(VENV)
|
|
|
|
|
if not (BINDIR / "python").is_file():
|
|
|
|
|
run(
|
|
|
|
|
sys.executable,
|
|
|
|
|
"-m",
|
|
|
|
|
"venv",
|
|
|
|
|
VENV,
|
|
|
|
|
label="Create the Coulobre virtual environment",
|
|
|
|
|
)
|
|
|
|
|
root_directory(BINDIR)
|
|
|
|
|
script = (
|
|
|
|
|
"from importlib.util import find_spec; "
|
|
|
|
|
"from importlib.metadata import distributions; "
|
|
|
|
|
"print(next((p.version for p in distributions() "
|
|
|
|
|
"if p.metadata['Name'] == 'coulobre-panel'), '')); "
|
|
|
|
|
"print(int(bool(find_spec('gunicorn') and find_spec('MySQLdb'))))"
|
|
|
|
|
)
|
|
|
|
|
installed, ready = run(
|
|
|
|
|
BINDIR / "python", "-c", script, label="Check the Coulobre version"
|
|
|
|
|
).splitlines()
|
|
|
|
|
if installed and installed != release:
|
|
|
|
|
raise InstallError("Use the source release matching /opt/coulobre.")
|
|
|
|
|
if installed and ready == "1":
|
|
|
|
|
return
|
|
|
|
|
with_extras = f"{SOURCE}[server,mariadb]"
|
2026-11-24 02:01:09 +01:00
|
|
|
if Path("/usr/share/coulobre-panel/source") == SOURCE:
|
|
|
|
|
bundled = (
|
|
|
|
|
SOURCE.parent
|
|
|
|
|
/ "wheel"
|
|
|
|
|
/ (f"coulobre_panel-{release}-py3-none-any.whl")
|
|
|
|
|
)
|
|
|
|
|
root_file(bundled, 0o644)
|
|
|
|
|
with_extras = f"{bundled}[server,mariadb]"
|
2026-11-22 16:39:27 +01:00
|
|
|
pip_env = {
|
|
|
|
|
key: os.environ[key]
|
|
|
|
|
for key in ("PIP_NO_INDEX", "PIP_FIND_LINKS")
|
|
|
|
|
if key in os.environ
|
|
|
|
|
}
|
2026-11-22 21:27:29 +01:00
|
|
|
with step("Installing Coulobre and its Python dependencies"):
|
2026-11-23 00:20:18 +01:00
|
|
|
run(
|
|
|
|
|
BINDIR / "python",
|
|
|
|
|
"-m",
|
|
|
|
|
"pip",
|
|
|
|
|
"install",
|
|
|
|
|
"--disable-pip-version-check",
|
|
|
|
|
"--only-binary=:all:",
|
|
|
|
|
"pip>=26.2",
|
|
|
|
|
label="Update the virtual environment installer",
|
|
|
|
|
env=pip_env,
|
|
|
|
|
timeout=1200,
|
|
|
|
|
)
|
2026-11-22 21:27:29 +01:00
|
|
|
run(
|
|
|
|
|
BINDIR / "pip",
|
|
|
|
|
"install",
|
|
|
|
|
"--disable-pip-version-check",
|
|
|
|
|
with_extras,
|
|
|
|
|
label="Install Coulobre and its Python dependencies",
|
|
|
|
|
env=pip_env,
|
|
|
|
|
timeout=1200,
|
|
|
|
|
)
|
2026-11-22 16:39:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@contextmanager
|
|
|
|
|
def install_lock():
|
|
|
|
|
root_directory(STATE, mode=0o700)
|
|
|
|
|
if stat.S_IMODE(STATE.stat().st_mode) != 0o700:
|
|
|
|
|
raise InstallError(f"Set mode 0700 on {STATE}.")
|
|
|
|
|
lock = os.open(
|
|
|
|
|
STATE / "lock", os.O_CREAT | os.O_NOFOLLOW | os.O_RDWR, 0o600
|
|
|
|
|
)
|
|
|
|
|
try:
|
|
|
|
|
try:
|
|
|
|
|
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
|
|
|
|
except BlockingIOError:
|
|
|
|
|
raise InstallError(
|
|
|
|
|
"A Coulobre installation is already running."
|
|
|
|
|
) from None
|
|
|
|
|
yield
|
|
|
|
|
finally:
|
|
|
|
|
os.close(lock)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Installer:
|
2026-11-26 22:10:34 +01:00
|
|
|
def __init__(
|
|
|
|
|
self, plan, password, progress, *, heartbeat=False, scopes=None
|
|
|
|
|
):
|
2026-11-22 16:39:27 +01:00
|
|
|
self.plan = plan
|
|
|
|
|
self.password = password
|
|
|
|
|
self.progress = progress
|
2026-11-22 21:27:29 +01:00
|
|
|
self.heartbeat = heartbeat
|
2026-11-26 22:10:34 +01:00
|
|
|
self.scopes = scopes or {}
|
2026-11-22 16:39:27 +01:00
|
|
|
self.state_file = STATE / "installation.json"
|
2026-12-01 14:17:13 +01:00
|
|
|
self.folder_sftp_supported = False
|
2026-11-22 16:39:27 +01:00
|
|
|
self.php, self.modern_mail = platform_settings()
|
|
|
|
|
with (SOURCE / "pyproject.toml").open("rb") as project:
|
|
|
|
|
self.release = tomllib.load(project)["project"]["version"]
|
|
|
|
|
|
2026-11-22 21:27:29 +01:00
|
|
|
@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."
|
|
|
|
|
)
|
|
|
|
|
|
2026-11-22 16:39:27 +01:00
|
|
|
def save_state(self):
|
|
|
|
|
put_file(
|
|
|
|
|
self.state_file,
|
|
|
|
|
json.dumps(self.state, indent=2) + "\n",
|
|
|
|
|
mode=0o600,
|
|
|
|
|
update=True,
|
|
|
|
|
)
|
|
|
|
|
|
2026-11-26 22:10:34 +01:00
|
|
|
def check_state(self):
|
2026-11-22 16:39:27 +01:00
|
|
|
expected = {"release": self.release, "plan": self.plan.record()}
|
2026-11-26 22:10:34 +01:00
|
|
|
if self.scopes:
|
|
|
|
|
expected["scopes"] = self.scopes
|
2026-11-22 16:39:27 +01:00
|
|
|
if self.state_file.exists():
|
|
|
|
|
root_file(self.state_file, 0o600)
|
2026-11-26 22:10:34 +01:00
|
|
|
state = json.loads(self.state_file.read_text(encoding="utf-8"))
|
|
|
|
|
current = {key: state.get(key) for key in expected}
|
|
|
|
|
if current != expected or state.get("scopes", {}) != self.scopes:
|
2026-11-22 16:39:27 +01:00
|
|
|
raise InstallError(
|
|
|
|
|
"Resume with the same installation settings and release."
|
|
|
|
|
)
|
2026-11-26 22:10:34 +01:00
|
|
|
return expected, state
|
|
|
|
|
if os.path.lexists(ENV_FILE):
|
|
|
|
|
raise InstallError(
|
|
|
|
|
"The panel already has a configuration. Use the upgrade guide."
|
|
|
|
|
)
|
|
|
|
|
return expected, {}
|
|
|
|
|
|
|
|
|
|
def read_state(self):
|
|
|
|
|
expected, self.state = self.check_state()
|
|
|
|
|
if not self.state:
|
2026-11-22 16:39:27 +01:00
|
|
|
self.state = expected | {
|
|
|
|
|
"secret_key": secrets.token_urlsafe(48),
|
|
|
|
|
"database_password": secrets.token_urlsafe(36),
|
|
|
|
|
"broker_password": secrets.token_urlsafe(36),
|
|
|
|
|
}
|
|
|
|
|
self.save_state()
|
|
|
|
|
|
2026-11-26 22:10:34 +01:00
|
|
|
def prepare_platform(self):
|
|
|
|
|
if self.state.get("platform_ready"):
|
|
|
|
|
return
|
|
|
|
|
self.progress("Installing system packages and the Coulobre release.")
|
|
|
|
|
mail = self.plan.mail
|
|
|
|
|
install_packages(
|
|
|
|
|
self.packages(),
|
|
|
|
|
mail_host=mail.host if mail.mode == "local" else "",
|
|
|
|
|
step=self.step,
|
|
|
|
|
)
|
|
|
|
|
install_release(self.release, step=self.step)
|
|
|
|
|
if self.scopes:
|
|
|
|
|
self.state["platform_ready"] = True
|
|
|
|
|
self.save_state()
|
|
|
|
|
|
|
|
|
|
def prepare_cluster_keys(self):
|
|
|
|
|
with install_lock():
|
|
|
|
|
self.read_state()
|
|
|
|
|
if not self.state.get("complete"):
|
|
|
|
|
self.prepare_platform()
|
|
|
|
|
return {
|
|
|
|
|
name: run(
|
|
|
|
|
BINDIR / "coulobre-node-setup",
|
|
|
|
|
"prepare-panel",
|
|
|
|
|
name,
|
|
|
|
|
label=f"Prepare the panel's {name} key",
|
|
|
|
|
).strip()
|
|
|
|
|
for name in self.scopes
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-22 16:39:27 +01:00
|
|
|
def packages(self):
|
|
|
|
|
packages = list(BASE_PACKAGES)
|
|
|
|
|
if self.php:
|
2026-12-01 14:17:13 +01:00
|
|
|
packages.extend((f"php{self.php}-fpm", "openssh-server"))
|
2026-11-22 16:39:27 +01:00
|
|
|
if self.plan.dns.mode == "local":
|
|
|
|
|
packages.extend(("bind9", "bind9-utils"))
|
|
|
|
|
if self.plan.mail.mode == "local":
|
|
|
|
|
packages.extend(
|
2026-11-22 17:51:05 +01:00
|
|
|
(
|
|
|
|
|
"postfix",
|
|
|
|
|
"dovecot-core",
|
|
|
|
|
"dovecot-imapd",
|
|
|
|
|
"dovecot-lmtpd",
|
|
|
|
|
"rspamd",
|
|
|
|
|
"redis-server",
|
|
|
|
|
)
|
2026-11-22 16:39:27 +01:00
|
|
|
)
|
2026-11-22 17:51:05 +01:00
|
|
|
if REMOTE_MODES.intersection(
|
|
|
|
|
(self.plan.dns.mode, self.plan.mail.mode)
|
|
|
|
|
):
|
2026-11-22 16:39:27 +01:00
|
|
|
packages.extend(("openssh-client", "socat"))
|
2026-11-22 17:51:05 +01:00
|
|
|
if self.plan.access == "acme" or (
|
|
|
|
|
self.plan.mail.mode == "local" and self.plan.mail.tls == "acme"
|
|
|
|
|
):
|
|
|
|
|
packages.append("certbot")
|
2026-11-22 16:39:27 +01:00
|
|
|
return packages
|
|
|
|
|
|
2026-11-22 17:51:05 +01:00
|
|
|
def install_certificates(self):
|
|
|
|
|
services = {}
|
|
|
|
|
if self.plan.access == "acme":
|
|
|
|
|
services[self.plan.hostname] = ["apache2.service"]
|
|
|
|
|
mail = self.plan.mail
|
|
|
|
|
if mail.mode == "local" and mail.tls == "acme":
|
|
|
|
|
services.setdefault(mail.host, []).extend(
|
|
|
|
|
("postfix.service", "dovecot.service")
|
|
|
|
|
)
|
|
|
|
|
if services:
|
|
|
|
|
self.progress(
|
|
|
|
|
"Requesting the selected Let's Encrypt certificates."
|
|
|
|
|
)
|
|
|
|
|
panel_host = (
|
|
|
|
|
self.plan.hostname if self.plan.access != "proxy" else ""
|
|
|
|
|
)
|
|
|
|
|
certificates.configure_webroot(services, panel_host)
|
|
|
|
|
for host, units in services.items():
|
|
|
|
|
certificates.issue(
|
|
|
|
|
host, self.plan.admin_email, units, webroot=True
|
|
|
|
|
)
|
|
|
|
|
|
2026-11-22 16:39:27 +01:00
|
|
|
def configure_stores(self):
|
|
|
|
|
put_file(
|
|
|
|
|
Path("/etc/mysql/mariadb.conf.d/90-coulobre-loopback.cnf"),
|
|
|
|
|
"[mariadbd]\nbind-address=127.0.0.1\n",
|
|
|
|
|
)
|
|
|
|
|
broker_config = Path("/etc/rabbitmq")
|
|
|
|
|
if any(
|
|
|
|
|
(broker_config / name).exists()
|
|
|
|
|
for name in ("rabbitmq.conf", "advanced.config")
|
|
|
|
|
) or any((broker_config / "conf.d").glob("*.conf")):
|
|
|
|
|
raise InstallError("Review the existing RabbitMQ configuration.")
|
|
|
|
|
put_file(
|
|
|
|
|
Path("/etc/coulobre-rabbitmq.conf"),
|
|
|
|
|
"listeners.tcp.1 = 127.0.0.1:5672\n",
|
|
|
|
|
)
|
|
|
|
|
drop_in = SYSTEMD / "rabbitmq-server.service.d"
|
|
|
|
|
root_directory(drop_in)
|
|
|
|
|
put_file(
|
|
|
|
|
drop_in / "coulobre.conf",
|
|
|
|
|
"[Service]\n"
|
|
|
|
|
"Environment=RABBITMQ_CONFIG_FILE=/etc/coulobre-rabbitmq.conf\n",
|
|
|
|
|
)
|
|
|
|
|
systemctl("daemon-reload")
|
2026-11-22 21:27:29 +01:00
|
|
|
for name, unit in (
|
|
|
|
|
("MariaDB", "mariadb.service"),
|
|
|
|
|
("RabbitMQ", "rabbitmq-server.service"),
|
|
|
|
|
):
|
|
|
|
|
with self.step(f"Starting {name} on loopback"):
|
2026-11-24 12:15:16 +01:00
|
|
|
try:
|
|
|
|
|
systemctl("enable", "--now", unit)
|
|
|
|
|
systemctl("restart", unit)
|
|
|
|
|
except InstallError:
|
|
|
|
|
self.progress(
|
|
|
|
|
f"Read the {name} service log with "
|
|
|
|
|
f"sudo journalctl -b -u {unit} -n 60 --no-pager"
|
|
|
|
|
)
|
|
|
|
|
raise
|
2026-11-22 16:39:27 +01:00
|
|
|
|
|
|
|
|
def mariadb(sql):
|
|
|
|
|
return run(
|
|
|
|
|
"mariadb",
|
|
|
|
|
"--batch",
|
|
|
|
|
"--skip-column-names",
|
|
|
|
|
"--protocol=socket",
|
|
|
|
|
source=sql.encode(),
|
|
|
|
|
label="Configure the local MariaDB database",
|
|
|
|
|
).strip()
|
|
|
|
|
|
|
|
|
|
if not self.state.get("stores_reserved"):
|
|
|
|
|
existing = mariadb(
|
|
|
|
|
"SELECT EXISTS(SELECT 1 FROM information_schema.schemata "
|
|
|
|
|
"WHERE schema_name='coulobre_panel') OR "
|
|
|
|
|
"EXISTS(SELECT 1 FROM mysql.user WHERE User='coulobre');"
|
|
|
|
|
)
|
|
|
|
|
if existing != "0":
|
|
|
|
|
raise InstallError(
|
|
|
|
|
"A Coulobre MariaDB database or user already exists."
|
|
|
|
|
)
|
|
|
|
|
for action in ("list_users", "list_vhosts"):
|
|
|
|
|
rows = run(
|
|
|
|
|
"rabbitmqctl", "--quiet", action, label="Inspect RabbitMQ"
|
|
|
|
|
)
|
|
|
|
|
if "coulobre" in {
|
|
|
|
|
row.split()[0] for row in rows.splitlines() if row.split()
|
|
|
|
|
}:
|
|
|
|
|
raise InstallError(
|
|
|
|
|
"A Coulobre RabbitMQ user or virtual host exists."
|
|
|
|
|
)
|
|
|
|
|
self.state["stores_reserved"] = True
|
|
|
|
|
self.save_state()
|
|
|
|
|
|
|
|
|
|
mariadb(
|
|
|
|
|
"CREATE DATABASE IF NOT EXISTS coulobre_panel "
|
|
|
|
|
"CHARACTER SET utf8mb4;"
|
|
|
|
|
"CREATE USER IF NOT EXISTS 'coulobre'@'localhost' IDENTIFIED BY "
|
|
|
|
|
f"'{self.state['database_password']}';"
|
|
|
|
|
"GRANT ALL PRIVILEGES ON coulobre_panel.* "
|
|
|
|
|
"TO 'coulobre'@'localhost';"
|
|
|
|
|
)
|
|
|
|
|
users = run(
|
|
|
|
|
"rabbitmqctl",
|
|
|
|
|
"--quiet",
|
|
|
|
|
"list_users",
|
|
|
|
|
label="Inspect RabbitMQ users",
|
|
|
|
|
)
|
|
|
|
|
if "coulobre" not in {
|
|
|
|
|
row.split()[0] for row in users.splitlines() if row.split()
|
|
|
|
|
}:
|
|
|
|
|
run(
|
|
|
|
|
"rabbitmqctl",
|
|
|
|
|
"add_user",
|
|
|
|
|
"coulobre",
|
|
|
|
|
source=(self.state["broker_password"] + "\n").encode(),
|
|
|
|
|
label="Create the Coulobre RabbitMQ login",
|
|
|
|
|
)
|
|
|
|
|
hosts = run(
|
|
|
|
|
"rabbitmqctl",
|
|
|
|
|
"--quiet",
|
|
|
|
|
"list_vhosts",
|
|
|
|
|
label="Inspect RabbitMQ virtual hosts",
|
|
|
|
|
)
|
|
|
|
|
if "coulobre" not in {row.strip() for row in hosts.splitlines()}:
|
|
|
|
|
run(
|
|
|
|
|
"rabbitmqctl",
|
|
|
|
|
"add_vhost",
|
|
|
|
|
"coulobre",
|
|
|
|
|
label="Create the Coulobre RabbitMQ virtual host",
|
|
|
|
|
)
|
|
|
|
|
run(
|
|
|
|
|
"rabbitmqctl",
|
|
|
|
|
"set_permissions",
|
|
|
|
|
"-p",
|
|
|
|
|
"coulobre",
|
|
|
|
|
"coulobre",
|
|
|
|
|
".*",
|
|
|
|
|
".*",
|
|
|
|
|
".*",
|
|
|
|
|
label="Grant access to the Coulobre virtual host",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def environment(self):
|
2026-11-22 22:27:08 +01:00
|
|
|
services = [
|
|
|
|
|
"panel",
|
|
|
|
|
"worker",
|
|
|
|
|
"scheduler",
|
|
|
|
|
"apache",
|
|
|
|
|
"mariadb",
|
|
|
|
|
"rabbitmq",
|
|
|
|
|
]
|
|
|
|
|
if self.php:
|
|
|
|
|
services.append("php-fpm")
|
|
|
|
|
if self.plan.dns.mode == "local":
|
|
|
|
|
services.append("bind9")
|
|
|
|
|
if self.plan.mail.mode == "local":
|
|
|
|
|
services.extend(("postfix", "dovecot", "rspamd", "redis"))
|
2026-11-22 16:39:27 +01:00
|
|
|
options = {
|
|
|
|
|
"DJANGO_SETTINGS_MODULE": "coulobre.settings",
|
|
|
|
|
"COULOBRE_ALLOWED_HOSTS": self.plan.hostname,
|
|
|
|
|
"COULOBRE_HTTPS_PROXY": "1",
|
|
|
|
|
"COULOBRE_REQUIRE_PRIVILEGED_MFA": "1",
|
2026-11-22 21:43:37 +01:00
|
|
|
"COULOBRE_PASSWORD_RESET_ORIGIN": f"https://{self.plan.hostname}",
|
2026-11-22 16:39:27 +01:00
|
|
|
"COULOBRE_TRUST_APACHE_CLIENT_IP": "1",
|
|
|
|
|
"COULOBRE_STATIC_ROOT": str(STATIC),
|
|
|
|
|
"COULOBRE_SECRET_KEY": self.state["secret_key"],
|
|
|
|
|
"COULOBRE_DB_NAME": "coulobre_panel",
|
|
|
|
|
"COULOBRE_DB_USER": "coulobre",
|
|
|
|
|
"COULOBRE_DB_PASSWORD": self.state["database_password"],
|
|
|
|
|
"COULOBRE_DB_HOST": "/run/mysqld/mysqld.sock",
|
|
|
|
|
"COULOBRE_BROKER_URL": (
|
|
|
|
|
f"amqp://coulobre:{self.state['broker_password']}@127.0.0.1:5672/coulobre"
|
|
|
|
|
),
|
|
|
|
|
"COULOBRE_LOCAL_DATABASE_PROVISIONING": "1",
|
2026-11-22 23:04:17 +01:00
|
|
|
"COULOBRE_SERVICE_HEALTH": (
|
|
|
|
|
"'"
|
|
|
|
|
+ json.dumps(
|
|
|
|
|
{"panel": {"local": services}}, separators=(",", ":")
|
|
|
|
|
)
|
|
|
|
|
+ "'"
|
2026-11-22 22:27:08 +01:00
|
|
|
),
|
2026-11-22 16:39:27 +01:00
|
|
|
}
|
|
|
|
|
if self.php:
|
|
|
|
|
options["COULOBRE_LOCAL_WEB_ACTIVATION"] = "1"
|
2026-11-22 17:51:05 +01:00
|
|
|
options["COULOBRE_WEBSITE_USAGE"] = "1"
|
2026-12-01 01:30:42 +01:00
|
|
|
options.update(
|
|
|
|
|
COULOBRE_WEB_FILE_MANAGER="1",
|
|
|
|
|
COULOBRE_WEBSITE_JOBS="1",
|
|
|
|
|
COULOBRE_LOCAL_ACCOUNT_BACKUPS="1",
|
2026-12-01 14:17:13 +01:00
|
|
|
COULOBRE_LOCAL_WEB_SFTP="1",
|
2026-12-01 01:30:42 +01:00
|
|
|
)
|
2026-12-01 14:17:13 +01:00
|
|
|
if self.folder_sftp_supported:
|
|
|
|
|
options["COULOBRE_LOCAL_FOLDER_SFTP"] = "1"
|
|
|
|
|
if self.plan.access != "proxy":
|
|
|
|
|
options["COULOBRE_SFTP_HOST"] = self.plan.hostname
|
2026-12-01 01:30:42 +01:00
|
|
|
if self.plan.access == "acme":
|
|
|
|
|
options["COULOBRE_LOCAL_WEB_HTTPS"] = "1"
|
2026-11-22 16:39:27 +01:00
|
|
|
if self.plan.dns.mode != "off":
|
|
|
|
|
options["COULOBRE_LOCAL_DNS_PUBLISHING"] = "1"
|
|
|
|
|
if self.plan.mail.mode != "off":
|
|
|
|
|
options["COULOBRE_LOCAL_MAILBOX_PROVISIONING"] = "1"
|
2026-12-01 02:04:33 +01:00
|
|
|
options["COULOBRE_MAILBOX_PASSWORD_CHANGES"] = "1"
|
2026-11-26 22:10:34 +01:00
|
|
|
if self.plan.mail.mode in {"local", "remote-install"} or (
|
|
|
|
|
"mail" in self.scopes
|
|
|
|
|
):
|
2026-11-22 17:51:05 +01:00
|
|
|
options["COULOBRE_MAIL_NODE_DKIM"] = "1"
|
2026-11-24 13:43:58 +01:00
|
|
|
if self.plan.mail.mail_hostname:
|
|
|
|
|
options.update(
|
|
|
|
|
COULOBRE_MAIL_IMAP_HOST=self.plan.mail.mail_hostname,
|
|
|
|
|
COULOBRE_MAIL_SUBMISSION_HOST=self.plan.mail.mail_hostname,
|
2026-11-24 13:41:06 +01:00
|
|
|
)
|
2026-11-22 21:43:37 +01:00
|
|
|
if self.plan.mail.mode == "local":
|
|
|
|
|
options.update(
|
|
|
|
|
COULOBRE_SMTP_HOST="127.0.0.1",
|
|
|
|
|
COULOBRE_SMTP_PORT="25",
|
|
|
|
|
COULOBRE_SMTP_STARTTLS="0",
|
|
|
|
|
COULOBRE_EMAIL_FROM=f"panel@{self.plan.mail.host}",
|
|
|
|
|
)
|
|
|
|
|
hosting = self.plan.hosting
|
|
|
|
|
if hosting.public_addresses:
|
|
|
|
|
options["COULOBRE_HOSTING_PUBLIC_ADDRESSES"] = ",".join(
|
|
|
|
|
hosting.public_addresses
|
|
|
|
|
)
|
|
|
|
|
if hosting.nameservers:
|
|
|
|
|
options["COULOBRE_HOSTING_NAMESERVERS"] = ",".join(
|
|
|
|
|
hosting.nameservers
|
|
|
|
|
)
|
|
|
|
|
if hosting.mail_sending_addresses:
|
|
|
|
|
options.update(
|
|
|
|
|
COULOBRE_MAIL_MX_HOST=self.plan.mail.mail_hostname,
|
|
|
|
|
COULOBRE_MAIL_SENDING_IPS=",".join(
|
|
|
|
|
hosting.mail_sending_addresses
|
|
|
|
|
),
|
|
|
|
|
COULOBRE_MANAGE_MAIL_DNS="1",
|
|
|
|
|
)
|
2026-11-22 16:39:27 +01:00
|
|
|
return "".join(f"{key}={value}\n" for key, value in options.items())
|
|
|
|
|
|
2026-11-22 21:43:37 +01:00
|
|
|
def verify_notification_mail(self):
|
|
|
|
|
if self.plan.mail.mode != "local":
|
|
|
|
|
return
|
|
|
|
|
try:
|
|
|
|
|
with smtplib.SMTP("127.0.0.1", 25, timeout=8) as relay:
|
|
|
|
|
relay.ehlo_or_helo_if_needed()
|
|
|
|
|
mail_code, _ = relay.mail(f"panel@{self.plan.mail.host}")
|
|
|
|
|
recipient_code, _ = relay.rcpt("smtp-check@example.invalid")
|
|
|
|
|
relay.rset()
|
|
|
|
|
if mail_code != 250 or recipient_code not in (250, 251):
|
|
|
|
|
raise OSError("Loopback SMTP relay rejected the envelope.")
|
|
|
|
|
except OSError as error:
|
|
|
|
|
raise InstallError(
|
|
|
|
|
"Local Postfix did not accept outgoing panel mail over "
|
|
|
|
|
"loopback. Check journalctl -u postfix and the relay policy."
|
|
|
|
|
) from error
|
|
|
|
|
|
2026-11-22 16:39:27 +01:00
|
|
|
def prepare_panel(self):
|
|
|
|
|
panel = identity("coulobre-panel")
|
|
|
|
|
root_directory(ETC, mode=0o750)
|
|
|
|
|
if not os.path.lexists(STATIC):
|
|
|
|
|
STATIC.mkdir(mode=0o755)
|
|
|
|
|
os.chown(STATIC, panel.pw_uid, panel.pw_gid)
|
|
|
|
|
info = STATIC.lstat()
|
|
|
|
|
if not stat.S_ISDIR(info.st_mode) or (info.st_uid, info.st_gid) != (
|
|
|
|
|
panel.pw_uid,
|
|
|
|
|
panel.pw_gid,
|
|
|
|
|
):
|
|
|
|
|
raise InstallError(
|
|
|
|
|
f"Check the directory and ownership of {STATIC}."
|
|
|
|
|
)
|
|
|
|
|
put_file(ENV_FILE, self.environment(), mode=0o600)
|
|
|
|
|
unit = (
|
|
|
|
|
"systemd-run",
|
|
|
|
|
"--quiet",
|
|
|
|
|
"--wait",
|
|
|
|
|
"--pipe",
|
|
|
|
|
"--collect",
|
|
|
|
|
"--uid=coulobre-panel",
|
|
|
|
|
"--property=EnvironmentFile=/etc/coulobre/panel.env",
|
|
|
|
|
str(BINDIR / "python"),
|
|
|
|
|
)
|
|
|
|
|
run(
|
|
|
|
|
*unit,
|
|
|
|
|
"-m",
|
|
|
|
|
"django",
|
|
|
|
|
"migrate",
|
|
|
|
|
"--noinput",
|
|
|
|
|
label="Apply panel migrations",
|
|
|
|
|
timeout=600,
|
|
|
|
|
)
|
|
|
|
|
run(
|
|
|
|
|
*unit,
|
|
|
|
|
"-m",
|
|
|
|
|
"django",
|
|
|
|
|
"collectstatic",
|
|
|
|
|
"--noinput",
|
|
|
|
|
label="Install panel static files",
|
|
|
|
|
)
|
|
|
|
|
info = {
|
|
|
|
|
"username": self.plan.admin_username,
|
|
|
|
|
"email": self.plan.admin_email,
|
|
|
|
|
"password": self.password,
|
|
|
|
|
}
|
|
|
|
|
run(
|
|
|
|
|
*unit,
|
|
|
|
|
"-c",
|
|
|
|
|
ADMIN_SCRIPT,
|
|
|
|
|
source=json.dumps(info).encode(),
|
|
|
|
|
label="Create the administrator account",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def apache(self):
|
|
|
|
|
modules = ["headers", "proxy", "proxy_http"]
|
|
|
|
|
if self.php:
|
|
|
|
|
modules.append("proxy_fcgi")
|
|
|
|
|
systemctl("enable", "--now", f"php{self.php}-fpm.service")
|
|
|
|
|
plan = self.plan
|
2026-11-22 17:51:05 +01:00
|
|
|
if plan.access in {"acme", "tls"}:
|
2026-11-22 16:39:27 +01:00
|
|
|
modules.append("ssl")
|
|
|
|
|
config = (ASSETS / "apache/panel-tls.conf.example").read_text()
|
|
|
|
|
config = (
|
|
|
|
|
config.replace("panel.example.net", plan.hostname)
|
|
|
|
|
.replace(
|
|
|
|
|
"/etc/ssl/coulobre-panel/fullchain.pem", plan.certificate
|
|
|
|
|
)
|
|
|
|
|
.replace("/etc/ssl/coulobre-panel/privkey.pem", plan.key)
|
|
|
|
|
)
|
2026-11-22 17:51:05 +01:00
|
|
|
if plan.access == "acme":
|
|
|
|
|
config = config[config.index("<VirtualHost *:443>") :]
|
2026-11-22 16:39:27 +01:00
|
|
|
else:
|
|
|
|
|
modules.append("remoteip")
|
|
|
|
|
local = (
|
|
|
|
|
f"[{plan.origin_ip}]"
|
|
|
|
|
if ":" in plan.origin_ip
|
|
|
|
|
else plan.origin_ip
|
|
|
|
|
)
|
|
|
|
|
config = (ASSETS / "apache/panel-origin.conf.example").read_text()
|
|
|
|
|
config = (
|
|
|
|
|
config.replace("panel.example.net", plan.hostname)
|
|
|
|
|
.replace("192.168.10.20:8080", f"{local}:{plan.origin_port}")
|
|
|
|
|
.replace("192.168.10.10", plan.proxy_ip)
|
|
|
|
|
)
|
|
|
|
|
put_file(
|
|
|
|
|
ETC / "panel-proxy.inc",
|
|
|
|
|
(ASSETS / "apache/panel-proxy.inc").read_text(),
|
|
|
|
|
)
|
|
|
|
|
put_file(
|
|
|
|
|
Path("/etc/apache2/sites-available/coulobre-panel.conf"), config
|
|
|
|
|
)
|
|
|
|
|
run("a2enmod", *modules, label="Enable the Apache modules")
|
|
|
|
|
run(
|
|
|
|
|
"a2ensite", "coulobre-panel", label="Enable the panel virtual host"
|
|
|
|
|
)
|
|
|
|
|
run(
|
|
|
|
|
"apache2ctl",
|
|
|
|
|
"configtest",
|
|
|
|
|
label="Validate the Apache virtual host",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def verify_panel(self):
|
|
|
|
|
request = (
|
|
|
|
|
f"GET /sign-in/ HTTP/1.0\r\nHost: {self.plan.hostname}\r\n"
|
|
|
|
|
"X-Forwarded-Proto: https\r\n\r\n"
|
|
|
|
|
).encode()
|
|
|
|
|
for _ in range(20):
|
|
|
|
|
try:
|
|
|
|
|
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as peer:
|
|
|
|
|
peer.settimeout(2)
|
|
|
|
|
peer.connect("/run/coulobre-panel/panel.sock")
|
|
|
|
|
peer.sendall(request)
|
|
|
|
|
with peer.makefile("rb") as reply:
|
|
|
|
|
if reply.readline(256).split()[1:2] == [b"200"]:
|
|
|
|
|
return
|
|
|
|
|
except OSError:
|
|
|
|
|
pass
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
raise InstallError(
|
|
|
|
|
"The panel did not respond. Check journalctl -u coulobre-panel."
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def install(self):
|
|
|
|
|
if os.geteuid() != 0 or not Path("/run/systemd/system").is_dir():
|
|
|
|
|
raise InstallError("Run the installer as root on a systemd host.")
|
|
|
|
|
with install_lock():
|
|
|
|
|
self.read_state()
|
|
|
|
|
if self.state.get("complete"):
|
|
|
|
|
self.progress(
|
|
|
|
|
"Coulobre is already installed with these settings."
|
|
|
|
|
)
|
|
|
|
|
self.verify_panel()
|
2026-11-22 21:43:37 +01:00
|
|
|
self.verify_notification_mail()
|
2026-11-22 16:39:27 +01:00
|
|
|
return
|
2026-11-26 22:10:34 +01:00
|
|
|
self.prepare_platform()
|
2026-11-22 17:51:05 +01:00
|
|
|
self.install_certificates()
|
2026-11-22 16:39:27 +01:00
|
|
|
self.progress("Preparing MariaDB and RabbitMQ on loopback.")
|
2026-11-22 21:27:29 +01:00
|
|
|
with self.step("Configuring database and message broker access"):
|
|
|
|
|
self.configure_stores()
|
2026-11-22 16:39:27 +01:00
|
|
|
self.progress(
|
|
|
|
|
"Configuring hosting service identities and provisioning."
|
|
|
|
|
)
|
|
|
|
|
workers = [
|
|
|
|
|
install_worker(
|
|
|
|
|
"coulobre-db-provisioning",
|
|
|
|
|
"coulobre-db-provisioner",
|
|
|
|
|
"coulobre-database-apply",
|
|
|
|
|
"coulobre-database-provisioner.service",
|
|
|
|
|
)
|
|
|
|
|
]
|
|
|
|
|
if self.php:
|
|
|
|
|
workers.append(
|
|
|
|
|
install_worker(
|
|
|
|
|
"coulobre-web-provisioning",
|
|
|
|
|
"coulobre-provisioner",
|
|
|
|
|
"coulobre-web-apply",
|
|
|
|
|
"coulobre-provisioner.service",
|
|
|
|
|
)
|
|
|
|
|
)
|
2026-11-22 17:51:05 +01:00
|
|
|
group("coulobre-usage-requests")
|
|
|
|
|
install_unit("coulobre-website-usage.socket")
|
|
|
|
|
install_unit("coulobre-website-usage@.service")
|
|
|
|
|
drop_in = SYSTEMD / "coulobre-provisioner.service.d"
|
|
|
|
|
root_directory(drop_in)
|
|
|
|
|
put_file(
|
|
|
|
|
drop_in / "website-usage.conf",
|
|
|
|
|
(
|
|
|
|
|
ASSETS
|
|
|
|
|
/ "systemd"
|
|
|
|
|
/ drop_in.name
|
|
|
|
|
/ "website-usage.conf"
|
|
|
|
|
).read_text(),
|
|
|
|
|
)
|
|
|
|
|
put_file(
|
|
|
|
|
Path("/etc/logrotate.d/coulobre-websites"),
|
|
|
|
|
(ASSETS / "logrotate/coulobre-websites").read_text(),
|
|
|
|
|
)
|
|
|
|
|
put_file(
|
|
|
|
|
Path(
|
|
|
|
|
"/etc/apache2/conf-available/coulobre-website-usage.conf"
|
|
|
|
|
),
|
|
|
|
|
(
|
|
|
|
|
ASSETS / "apache/coulobre-website-usage.conf"
|
|
|
|
|
).read_text(),
|
|
|
|
|
)
|
|
|
|
|
run(
|
|
|
|
|
"a2enconf",
|
|
|
|
|
"coulobre-website-usage",
|
|
|
|
|
label="Enable website usage logging",
|
|
|
|
|
)
|
|
|
|
|
workers.append("coulobre-website-usage.socket")
|
2026-12-01 14:17:13 +01:00
|
|
|
features = [
|
|
|
|
|
"website-files",
|
|
|
|
|
"website-jobs",
|
|
|
|
|
"account-backups",
|
|
|
|
|
"website-sftp",
|
|
|
|
|
"folder-sftp",
|
|
|
|
|
]
|
2026-12-01 01:30:42 +01:00
|
|
|
if self.plan.access == "acme":
|
|
|
|
|
features.append("website-https")
|
2026-12-01 14:17:13 +01:00
|
|
|
local_workers = run(
|
|
|
|
|
BINDIR / "python",
|
|
|
|
|
"-m",
|
|
|
|
|
"coulobre.local_feature_setup",
|
|
|
|
|
"--skip-unsupported-folder-sftp",
|
|
|
|
|
ASSETS,
|
|
|
|
|
*features,
|
|
|
|
|
label="Configure local hosting tools",
|
2026-12-01 15:01:45 +01:00
|
|
|
failure=lambda _code, stderr: (
|
|
|
|
|
stderr.decode("utf-8", errors="replace")
|
|
|
|
|
.strip()
|
|
|
|
|
.splitlines()[-1][:400]
|
|
|
|
|
if stderr.strip()
|
|
|
|
|
else "Check the local hosting tools and retry."
|
|
|
|
|
),
|
2026-12-01 14:17:13 +01:00
|
|
|
).splitlines()
|
|
|
|
|
workers.extend(local_workers)
|
|
|
|
|
self.folder_sftp_supported = (
|
|
|
|
|
"coulobre-folder-sftp.socket" in local_workers
|
2026-12-01 01:30:42 +01:00
|
|
|
)
|
2026-12-01 14:17:13 +01:00
|
|
|
if not self.folder_sftp_supported:
|
|
|
|
|
self.progress(
|
|
|
|
|
"Folder SFTP needs a filesystem with ID-mapped mount "
|
|
|
|
|
"support. Website SFTP is available."
|
|
|
|
|
)
|
2026-11-22 16:39:27 +01:00
|
|
|
for name in ("dns", "mail"):
|
|
|
|
|
target = getattr(self.plan, name)
|
|
|
|
|
if target.mode != "off":
|
|
|
|
|
workers.append(roles.configure_role(self, name, target))
|
2026-12-01 02:04:33 +01:00
|
|
|
if self.plan.mail.mode != "off":
|
|
|
|
|
workers.extend(
|
|
|
|
|
run(
|
|
|
|
|
BINDIR / "python",
|
|
|
|
|
"-m",
|
|
|
|
|
"coulobre.local_feature_setup",
|
|
|
|
|
ASSETS,
|
|
|
|
|
"mailbox-passwords",
|
|
|
|
|
label="Configure mailbox password changes",
|
|
|
|
|
).splitlines()
|
|
|
|
|
)
|
2026-11-22 16:39:27 +01:00
|
|
|
self.progress(
|
|
|
|
|
"Applying panel migrations and creating the administrator."
|
|
|
|
|
)
|
|
|
|
|
self.prepare_panel()
|
|
|
|
|
self.progress("Validating Apache and starting the panel services.")
|
|
|
|
|
self.apache()
|
2026-11-22 22:27:08 +01:00
|
|
|
identity("coulobre-health")
|
|
|
|
|
for unit in (
|
|
|
|
|
*PANEL_UNITS,
|
|
|
|
|
"coulobre-health.service",
|
|
|
|
|
HEALTH_TIMER,
|
|
|
|
|
):
|
2026-11-22 16:39:27 +01:00
|
|
|
install_unit(unit)
|
2026-11-23 23:27:02 +01:00
|
|
|
workers.append(
|
|
|
|
|
install_worker(
|
|
|
|
|
"coulobre-operator",
|
|
|
|
|
"coulobre-operator",
|
|
|
|
|
"coulobre-operator-apply",
|
|
|
|
|
"coulobre-operator-worker.service",
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
workers.append("coulobre-operator-apply.socket")
|
2026-11-23 00:20:18 +01:00
|
|
|
install_unit("coulobre-update.socket")
|
|
|
|
|
install_unit("coulobre-update@.service")
|
|
|
|
|
workers.append("coulobre-update.socket")
|
2026-11-24 02:01:09 +01:00
|
|
|
if Path("/usr/share/coulobre-panel/source") == SOURCE:
|
|
|
|
|
workers.append("coulobre-remote-deploy.socket")
|
2026-11-22 16:39:27 +01:00
|
|
|
systemctl("daemon-reload")
|
|
|
|
|
systemctl(
|
|
|
|
|
"enable", "--now", *PANEL_UNITS, *workers, "apache2.service"
|
|
|
|
|
)
|
|
|
|
|
systemctl("reload", "apache2.service")
|
2026-11-22 22:27:08 +01:00
|
|
|
systemctl("enable", "--now", HEALTH_TIMER)
|
2026-11-22 16:39:27 +01:00
|
|
|
self.verify_panel()
|
2026-11-22 21:43:37 +01:00
|
|
|
if self.plan.mail.mode == "local":
|
|
|
|
|
with self.step("Checking Postfix for outgoing panel email"):
|
|
|
|
|
self.verify_notification_mail()
|
2026-11-22 16:39:27 +01:00
|
|
|
for key in ("secret_key", "database_password", "broker_password"):
|
|
|
|
|
self.state.pop(key, None)
|
|
|
|
|
self.state["complete"] = True
|
|
|
|
|
self.save_state()
|
|
|
|
|
self.progress(
|
|
|
|
|
f"Installation complete. Sign in at https://{self.plan.hostname}/"
|
|
|
|
|
)
|