Skip to content

Refactor aos-unit systemd architecture for idempotent restarts and native orchestration #11

Description

@klogg

Background & Problem Statement

Currently, restarting the main aos-unit.service causes race conditions and crashes (e.g., Unit already exists or service is already running). This occurs because systemd's transaction engine optimizes systemctl restart by merging jobs, aggressively auto-restarting dynamically linked transient units (dnsmasq, node_xxx) in parallel with our ExecStartPre configuration scripts.

To fix this, we need to stop fighting systemd's state engine and transition to an idempotent infrastructure model utilizing native systemd orchestration primitives (Template Units, Idempotent Re-use, and strict unit encapsulation).

Proposed Architecture Changes

Route Monitor Integration (Main Service Daemon)

Instead of spawning aos-unit-route-monitor as a fragile transient unit and holding the main service open with sleep infinity, we will elevate the route monitor to be the primary daemon.

Phase 2: DNSMasq Network Encapsulation & Idempotent Re-use

Systemd will relentlessly auto-restart transient units with BindsTo= during a fast restart. We will implement the "Idempotent Re-use" pattern to absorb this behavior rather than crashing.

Phase 3: Transition VMs to Systemd Template Units

Replace imperative systemd-run VM spawning with declarative Systemd Template Units to eliminate "Unit already exists" deadlocks entirely.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions