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.
Background & Problem Statement
Currently, restarting the main
aos-unit.servicecauses race conditions and crashes (e.g.,Unit already existsorservice is already running). This occurs because systemd's transaction engine optimizessystemctl restartby merging jobs, aggressively auto-restarting dynamically linked transient units (dnsmasq,node_xxx) in parallel with ourExecStartPreconfiguration 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-monitoras a fragile transient unit and holding the main service open withsleep 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-runVM spawning with declarative Systemd Template Units to eliminate "Unit already exists" deadlocks entirely.