Adversarial parity review of every ported action against its bash source confirmed 17 real behavioral drifts (of 22 claimed); all fixed here: - tiers/chown: defaults were compositions/apex/tierN (one level too deep); now the tier roots. shared/ base reset is non-recursive again. - compose: --dry-run was swallowed by argparse.REMAINDER; now stripped. - host.write_file: rendered files land 0644 (tempfile's 0600 made fresh systemd units/crowdsec configs owner-only). - systemd.deploy_units: top-level non-hidden files only. - ufw: missing docker/host config dir exits 66; missing /etc/ufw target aborts; empty rules dir warns; dotfile .rules excluded. - sync/packages: Telegram error-trap parity and failed notify exits 1. Same notify-failure exit for backup/run and sync/repository. repository regains the node-dir guard. - tiers/useradd: no more secret-bearing .env.bak per run. - tiers/link: EOF on confirm prompt declines and continues. - extract-traefik-certs: sudo mkdir inside the notify envelope. - generate-happ-subscriptions: realpath parent-exists guards + docker check. - configure/crowdsec: bouncer install goes through install_packages. - lint-docker-compose: malformed/unreadable anchor-IP inputs are lint errors. - core compose: APEX_RESTIC_REPOSITORY now ?error; RESTIC_COMPRESSION per-node via APEX_RESTIC_COMPRESSION (default auto). - sys.service_exists line-anchored; tpl docstring corrected.
27 lines
1.3 KiB
Python
27 lines
1.3 KiB
Python
# engine/lib/systemd.py
|
|
"""ctx.systemd — render + install unit files, daemon-reload, enable+start."""
|
|
from __future__ import annotations
|
|
import os
|
|
|
|
|
|
class Systemd:
|
|
def __init__(self, log, sys_, tpl, host):
|
|
self.log, self.sys, self.tpl, self.host = log, sys_, tpl, host
|
|
|
|
def deploy_units(self, configs_subdir: str, vars: dict, dry_run: bool = False) -> None:
|
|
# Top-level, non-hidden files only — the bash glob ("$CONFIG_DIR"/* + [[ -f ]])
|
|
# never recursed nor picked up dotfiles like .gitkeep.
|
|
rendered = {rel: c for rel, c in self.tpl.render_dir(configs_subdir, vars).items()
|
|
if "/" not in rel and not rel.startswith(".")}
|
|
if not rendered:
|
|
self.log.warn(f"No systemd units found under configs/{configs_subdir}.")
|
|
return
|
|
for rel, content in sorted(rendered.items()):
|
|
name = os.path.basename(rel)
|
|
self.host.write_file(f"/etc/systemd/system/{name}", content,
|
|
backup=True, dry_run=dry_run, sudo=True)
|
|
if name.endswith(".service") and not dry_run:
|
|
self.sys.daemon_reload()
|
|
self.sys.ensure_running(name[: -len(".service")])
|
|
self.log.success(f"Service {name[:-8]} active and enabled.")
|