Skip to content

metald: the daemon entrypoint

For Go code, follow the repository Go anti-pattern rules.

metal SPEC · overview: docs/architecture.md

Purpose

Command metald loads host configuration, creates runtime services, and starts the HTTPS servers. It is the composition root.

Command

text
metald serve [--config path]

The default configuration path is /var/lib/metal/metald.toml. A missing default file is permitted.

Types

TypeRole
optionsResolved runtime, listener, TLS, authentication, and base-directory settings.
fileConfigTOML sections for Metal and its runtime services.
tlsConfigurationsTLS settings for the Atlas API, coordination server, and node client.

Startup wiring

Architecture diagram
Loading diagram...

The storage constructor receives the daemon context, pool, image directory, and logger. It returns the pool, VM, image, and snapshot stores.

The network constructor receives optional mesh and traffic monitor services. The VM manager receives the runtime, network, storage, snapshot, optional traffic monitor, and logger services.

The host service receives an optional mesh service, WireGuard, image, VM, storage, and reconciler services. The API receives this service as one dependency.

Both servers require a client certificate from the regional authority. The Atlas API also pins tls.atlas_common_name, because a node certificate is valid for client use on the coordination API.

The source starts a one-shot mutual-TLS listener on migration.transfer_port for each snapshot. The listener uses the coordination address host and port 9002 by default, so metald.coordination_listen needs one node IP address and not a wildcard host. The destination verifies the source WireGuard IP before it receives the stream.

connectMesh runs on every start when wg_mesh.enabled is true. Each VM reconciliation calls Network.Ensure to restore and update its network.

wg_mesh.enabled = false does not disable managed WireGuard peers.

wg_mesh.uplink has no default. The Atlas WG Mesh NDP hook and its proxy NDP entries attach to this interface, so it must name the shared VLAN itself and never its parent. Only the controller knows which interface carries Atlas NDP, so metald requires the name.

Config keys

KeyDefaultMeaning
metald.base_dir/var/lib/metalStores machines, images, policies, peers, and staging files.
metald.listen127.0.0.1:8080TCP address or unix:/path.
metald.coordination_listen127.0.0.1:9001Mutual-TLS node coordination address.
tls.ca_filenoneRequired regional Metal authority certificate.
tls.certificate_filenoneRequired node certificate.
tls.private_key_filenoneRequired node private key.
tls.atlas_common_namenoneRequired common name of the Atlas client certificate.
firecracker.binary_path/usr/bin/firecrackerFirecracker binary.
firecracker.sockets_dir/run/metalShort API socket links.
jailer.binary_path/usr/bin/jailerJailer binary.
zfs.poolmetalZFS pool name.
wireguard.interfacewg0Underlay interface for managed peers and Atlas WG Mesh.
wg_mesh.enabledtrueEnables Atlas WG Mesh host setup and VM mesh registration.
wg_mesh.binary_path/usr/local/bin/atlas-wg-meshAtlas WG Mesh CLI. Required.
wg_mesh.uplinknonePrivate network interface that carries Atlas NDP. Required.
traffic_monitor.enabledtrueEnables VM packet monitoring and idle shutdown.
migration.final_delta_mib512Incremental size at or below which the destination stops the source and takes the final snapshot.
migration.transfer_port9002Mutual-TLS snapshot stream port. Use the same value on every host in the region.

See config.example.toml for the complete file format.

Runtime loops

The VM reconciler processes desired VM states. The image reconciler downloads cached images, creates warm artifacts, and removes idle local data. When traffic monitoring is enabled, one traffic listener dispatches each restoration in a separate daemon-owned goroutine.

The daemon owns all reconcilers, source stream processes, and snapshot upload jobs. SIGINT or SIGTERM starts a bounded graceful shutdown. It stops both HTTPS servers, cancels workers, closes console sessions, and closes host services. It does not stop or destroy guest virtual machines.

The daemon writes structured JSON logs. Log records include request and operation correlation fields when the operation comes from the API.

AGPL-3.0