Both gRPC listeners took their bind address from a -listen flag default alone, with no config key. The port a service binds and the port its clients dial were therefore two separate facts -- the flag default, and [services.<name>].target -- with nothing keeping them in step. On a host that already owned the default the effect read as a code fault rather than a port collision: the store died with "bind: address already in use" while every client reported "state store: connection error ... error reading server preface: EOF". Cockpit binds 9090 by default, so this is not hypothetical. Verifying the dashboard on such a host needed a hand-written overlay plus a matching -listen, two things to keep in step by hand. - [services.state].listen and [services.gateway].listen now name the bind address. Precedence is -listen, then config, then a default applied by the loader. An empty result is a startup ERROR, never a fallback: net.Listen reads "" as "any free port", so defaulting there would bind the service somewhere no client looks and still report success. - Both flag defaults become "" so configuration can win, mirroring how archie-ui already prefers [web].listen over its flag. - Gateway listen defaults to the same constant as the gateway target, so a default deployment's client and server cannot drift onto different ports. [services.state].target still has no default: an empty target stays a startup error in the daemon and gateway, which no longer serve a local store. - ServiceConnection gains the field. Its doc now says clients read only Target and TargetToken, and Listen belongs to the process that owns the service -- the previous wording claimed the struct starts no listeners while carrying one. - deployments/dev.toml states each port once, beside the target it must match, so `task dev` is retargetable on a host that owns 9090 by editing one overlay. Tests. Unit: config defaults, explicit values, and precedence. Process: the existing real-process smoke test now takes its listen from configuration instead of -listen, so the end-to-end wiring is proven by the test that already starts the binary, with no extra process. Both were verified load-bearing by mutation -- inverting the precedence fails the unit test, and making the app layer ignore config fails the process test with "state: no listen address". Verified: task check exit 0. Also documented in config.example.toml, the configuration architecture table, and the `task dev` summary.
36 lines
1.9 KiB
Go
36 lines
1.9 KiB
Go
package config
|
|
|
|
// Services selects contract adapters at application composition time.
|
|
type Services struct {
|
|
Gateway ServiceConnection `toml:"gateway" yaml:"gateway"`
|
|
// State selects the State Store contract adapter. The State Store is its
|
|
// own process (cmd/archie-state-store) and owns archie.db; an empty Target
|
|
// is a startup error in archied/archie-gateway, which no longer serve a
|
|
// local store (docs/prds/state-store-contract.md §12 step 7). The daemon
|
|
// and agent dial the remote StateStoreService and present target_token
|
|
// when the target is non-loopback. Token resolution mirrors the daemon's:
|
|
// the explicit key, then the STATE_STORE_TOKEN secret/env var.
|
|
State ServiceConnection `toml:"state" yaml:"state"`
|
|
}
|
|
|
|
// ServiceConnection is a contract adapter's gRPC address plus the bearer
|
|
// token a client presents when the target is non-loopback. A client reads only
|
|
// Target and TargetToken; Listen belongs to the process that owns the service.
|
|
// The struct does not itself register services or start listeners. Changes
|
|
// require a daemon restart.
|
|
type ServiceConnection struct {
|
|
Target string `toml:"target" yaml:"target"`
|
|
// Listen is the address the process that OWNS this service binds
|
|
// (archie-state-store, archie-gateway). It is read only by that process;
|
|
// every client ignores it. Defaulted, so a loaded config is never empty
|
|
// here -- an empty address reaches net.Listen as "any free port", which
|
|
// would silently move the service off the address its clients dial.
|
|
Listen string `toml:"listen" yaml:"listen"`
|
|
// TargetToken is the bearer token a client (daemon or agent) presents
|
|
// when dialing a non-loopback service target, and the standalone
|
|
// archie-state-store server validates. Empty means no token, which is
|
|
// the loopback-only, daemon-only listener topology permitted without
|
|
// auth (docs/prds/state-store-contract.md §9).
|
|
TargetToken string `toml:"target_token" yaml:"target_token"`
|
|
}
|