Expand description
Persistent server instance identity.
Every mold serve endpoint gets a stable UUIDv4, generated on first boot
and persisted in the metadata DB’s settings table. Clients (desktop
multi-host, discovery) use it to recognise the same server across
hostname/IP changes — it is surfaced in GET /api/status and the mDNS
id TXT record.
The identity is scoped per (data dir, serving port): two servers sharing
one mold.db (e.g. the desktop’s embedded server next to a standalone
mold serve on the same box) listen on different ports and must report
distinct ids, while one server keeps its id across restarts and address
changes because its port is stable.
Constants§
- SERVER_
INSTANCE_ ID_ KEY - Legacy port-less settings key from before identity was port-scoped. Never written anymore; its value is adopted (renamed) by the first port that resolves an id so existing installs keep their identity.
Functions§
- instance_
id_ key - Port-scoped settings key holding the installation UUID. Like
mold_db::settings::ACTIVE_PROFILE, this is identity metadata — it is always read and written underDEFAULT_PROFILEso the id never varies withMOLD_PROFILE. - resolve_
instance_ id - Resolve the persistent instance id for the server listening on
port, generating and storing one on first boot. A legacy port-less id (written by older versions) is adopted by the first port that asks — renamed to the port-scoped key so a second server on the same DB mints its own id instead of colliding. When the metadata DB is unavailable (MOLD_DB_DISABLE=1, open failure), falls back to a fresh ephemeral UUID — callers resolve once at startup and hold the result, making the fallback per-process.