Configuration and reload
Martin turns command-line values and a YAML file into one live configuration for the server, its map sources, and its map resources. It resolves deployment values before startup, applies source-specific policy to each published source, and keeps source data current through watchers and polls without re-reading the whole server configuration. See Martin server runtime, HTTP APIs and map resources, and source catalog and lifecycle for related system views.
Configuration model
Martin configuration has two linked roles. Server settings define the public service, while source and resource settings define the data that the service can publish.
Startup resolution
Startup builds the live state in a fixed order:
- Load the file named by
--config, when one is set. - Merge command-line overrides and positional source connections.
- Apply defaults and check related values such as URL paths, tile grids, and source settings.
- Warn about keys that no enabled section recognizes.
- Open sources and resources, then create the live catalog.
The file and command line are alternate inputs to the same configuration. A config file cannot be combined with positional source connections, but server overrides can still change values from that file. --save-config writes the effective configuration and adds the sources that are currently in the catalog.
Server settings cover the HTTP boundary and request policy. They include listen addresses, route prefixes, request and shutdown limits, compression, cache headers, CORS, optional endpoints, and optional monitoring or web UI access.
Martin also accepts named tile grids. A source can use a named grid when its data can be served in that coordinate system. OpenStreetMap PBF and shapefile entries are different: they describe bulk input for copy or generation commands and do not publish live HTTP tile sources during normal server startup.
References: crates/…/root.rs• L81-225 crates/…/config.rs• L96-240 crates/…/lifecycle.rs• L66-140 crates/…/lifecycle.rs• L201-282
Configuration diagnostics
Configuration errors identify the part of the input that needs attention. YAML syntax and type errors retain the file and value location, while substitution and source setup errors use separate diagnostic categories.
Unknown keys are kept while Martin reads each section. Finalization lets the owning section claim keys that it supports, then reports the remaining names as full dotted paths. This makes a misspelled nested key visible instead of silently changing the default behavior.
The on_invalid policy controls recoverable source failures. abort is the default and stops startup or a reload apply when a source cannot be accepted. warn keeps valid sources available and reports the invalid ones.
References: crates/…/error.rs• L18-72 crates/…/error.rs• L163-249 crates/…/config.rs• L350-397 crates/…/lifecycle.rs• L189-199 crates/…/collect_unrecognized.rs• L33-105
Configuration primitives
Martin uses common value shapes so short configuration forms can expand into detailed forms without changing the surrounding section.
| Primitive | Meaning |
|---|---|
| One-or-many | A field accepts no value, one value, or a list. Martin uses one internal list form. |
| Auto option | A feature can use defaults, be disabled, or use explicit settings. Boolean and keyword shorthands select the first two states. |
| Path-or-config | A file-backed section accepts one path, a list of paths, or a map with paths, collections, sources, and source-kind settings. |
| Source entry | A named source accepts a path or an object with a path and source policy. |
| ID resolution | Martin makes discovered IDs safe and unique. Reserved or repeated IDs receive a suffix. |
These forms preserve an important difference between an omitted value and an explicit disable. That difference lets a lower level inherit a default while still allowing a source to turn a feature off.
Cache and feature states
Cache policy uses either a zoom range or the literal disable. A disabled policy is explicit, so a later default does not turn it back on. The same three-state idea is used by conversion and optional feature settings: auto uses the normal default, disabled turns the feature off, and an object selects explicit behavior.
References: crates/…/one_or_many.rs• L8-18 crates/…/one_or_many.rs• L26-89 crates/…/auto_option.rs• L9-19 crates/…/auto_option.rs• L44-85 crates/…/file_config.rs• L100-170 crates/…/file_config.rs• L906-1029
File-backed settings
File-backed settings turn files, directories, and remote locations into named resources or tile sources. Each source kind decides which locations it supports and how those locations are discovered.
Paths and source entries
paths discovers files or directories. collections treats each immediate child directory as a named group. sources assigns a stable ID and can attach policy to one file or URL. A path-derived source gets an ID from its location.
An explicit entry remains authoritative when the same location also appears under a discovery path. This prevents a configured ID and its source policy from becoming a second auto-discovered source. Local and remote locations are kept distinct because local data can use filesystem events while remote data needs object-store listing or metadata checks.
References: crates/…/file_config.rs• L173-191 crates/…/file_config.rs• L239-281 crates/…/file_config.rs• L408-444 crates/…/source_location.rs• L9-42
Resource files
Styles, sprites, and fonts use the same path and collection model but publish map resources instead of tile sources. Explicit style sources must name files. Directories belong under styles.paths or styles.collections, where Martin discovers JSON styles and assigns their resource IDs.
Style rendering is an optional resource capability. Its settings describe whether rendering is enabled and set the render pool, tile size, pixel ratios, image quality, palette behavior, and ambient cache. The rendering service consumes the resolved values after startup.
References: crates/…/styles.rs• L24-92 crates/…/styles.rs• L214-317
Bulk input files
OpenStreetMap PBF and shapefile settings describe inputs for bulk processing. Their layer rules define which features and attributes enter the generated output, but these settings are outside the live HTTP source catalog.
References: crates/…/osm.rs• L12-70 crates/…/config.rs• L202-217
Source-specific settings
Source-specific settings let Martin apply safe defaults broadly and then change only the sources that need different behavior. The effective value normally follows per-source settings, source-kind or connection settings, global settings, and then the built-in default.
Tile processing
Tile processing settings control response format conversion and source response policy. MVT-to-MLT and MLT-to-MVT settings use the auto, disabled, or explicit forms. A source-level choice overrides its source kind and global choices, while cache-control resolves independently at the same levels.
The resolved result is attached to each catalog source. This keeps request negotiation and metadata aligned with the output that Martin actually serves. Hillshade and contour settings are source-specific because they describe the input tile data and change the advertised result.
References: crates/…/process.rs• L24-108 crates/…/process.rs• L172-264 crates/…/lifecycle.rs• L476-655
PostgreSQL sources
PostgreSQL configuration combines connection policy with table and function source policy. Automatic discovery reads the current database catalog and can publish tables, functions, or a selected set of schemas. Explicit entries add stable names and detailed source settings.
The connection or table can select a tile grid. Martin checks the source coordinate system before publishing it. Table settings can also define output layers, feature rules, attributes, and whole-tile operations. These controls let one database relation produce a client-facing map source without changing the database schema.
References: crates/…/config.rs• L60-181 crates/…/config.rs• L220-337 crates/…/config_table.rs• L26-156 crates/…/mod.rs• L28-57 crates/…/mod.rs• L120-257
DuckDB and GeoParquet sources
DuckDB configuration supports database files and GeoParquet locations. A database can publish tables and table macros through automatic discovery, while a GeoParquet entry describes one output layer and its local or remote data location.
Pool, thread, memory, bounds, cache, processing, and object-store values provide shared defaults. A source entry can override them. Local GeoParquet entries can be rebuilt when their files change; remote GeoParquet entries use their remote access settings but are not part of the local filesystem watcher.
References: crates/…/config.rs• L40-135 crates/…/auto_publish.rs• L8-28 crates/…/geoparquet.rs• L20-29 crates/…/geoparquet.rs• L89-135 crates/…/resolve.rs• L127-157
COG sources
COG settings support direct raster files and logical sources built from mosaics, STAC searches, or tile indexes. These choices describe how Martin finds raster data and how it presents the resulting tiles.
Raster encoding settings select PNG, WebP, or JPEG output. Quality and background settings must match that format, and an output format cannot be combined with a source conversion that already encodes the result. File and search expiry settings let a logical source notice replaced files or refreshed search results without rebuilding the server configuration.
References: crates/…/cog.rs• L34-85 crates/…/cog.rs• L97-215 crates/…/cog.rs• L223-287 crates/…/cog.rs• L337-432 crates/…/cog.rs• L508-575
Remote object-store settings
Remote PMTiles and COG sources share settings for cloud credentials, endpoints, request behavior, and HTTP clients. DuckDB uses the same settings when a remote GeoParquet location needs a DuckDB S3 secret.
Explicit values take precedence over process environment values and AWS profile values. Plain HTTP is refused unless allow_http is enabled. Saved configuration keeps useful connection settings but removes credentials and strips credentials from proxy URLs.
Credential providers can remain live for temporary credentials. They refresh credentials near expiry instead of placing short-lived secrets in saved configuration.
References: crates/…/object_store.rs• L38-110 crates/…/object_store.rs• L222-295 crates/…/object_store.rs• L344-413 crates/…/object_store.rs• L446-505 crates/…/object_store.rs• L711-760
Environment resolution
Martin expands environment values while it parses a configuration file. It builds a property map from the process environment and substitutes variables in plain YAML scalars before normal type conversion.
The supported forms include $NAME, ${NAME}, and shell-style alternatives such as ${NAME:-fallback}, ${NAME-fallback}, and ${NAME:+value}. A missing variable is an error when no alternative supplies a value. Quoted scalars and comments keep their literal text.
Object-store settings have a later provider-specific step. Standard AWS values fill missing settings, and AWS credential-discovery values apply when no profile is set. Explicit configuration wins over both. A profile can provide a region or credential provider only where explicit settings do not already decide those values.
References: crates/…/parse.rs• L10-33 crates/…/env.rs• L7-43 crates/…/parse.rs• L457-517 crates/…/object_store.rs• L227-295 crates/…/object_store.rs• L446-505
Runtime reload
Runtime reload keeps the live source catalog aligned with databases, local files, and remote locations. It does not re-read the complete server configuration file, so changes to server settings or source declarations still require a restart.
Reload triggers
Each source kind uses a trigger that matches its data location:
| Source kind or location | Trigger | Result |
|---|---|---|
| PostgreSQL | Periodic catalog discovery | Adds, updates, or removes published tables and functions. |
| Local PMTiles, MBTiles, GeoJSON, and COG paths | Filesystem events followed by discovery | Finds added, changed, and removed files. |
| Remote PMTiles and COG prefixes | Periodic object-store listing | Finds new, replaced, and removed objects. |
| Configured remote COG objects | Periodic metadata checks | Rebuilds a source when its object version changes. |
| Local GeoParquet entries | Filesystem events plus modification times | Rebuilds changed files and removes missing files. |
| Local DuckDB database files | No live catalog reload driver | The database sources loaded at startup remain the live view. |
PostgreSQL, PMTiles, and COG remote polling use a reload_interval. The default is ten minutes for the relevant source settings, and 0s disables polling. Local filesystem watchers do not use this interval.
The reload system starts after initial source loading. Requests for a source that is still loading wait until the catalog marks initial loading complete.
References: crates/…/reloaders.rs• L19-43 crates/…/reloaders.rs• L167-206 crates/…/trigger.rs• L17-43 crates/…/trigger.rs• L91-121 crates/…/postgres.rs• L21-27 crates/…/pmtiles.rs• L16-20 crates/…/cog.rs• L15-24 crates/…/duckdb.rs• L17-67
Reload reconciliation
Every reload driver keeps the last successful discovery as its baseline. A new discovery becomes an advisory with additions, updates, and removals. Versioned sources update when their version changes; sources without a useful version use set differences.
The driver builds changed sources before applying the advisory. A discovery or apply failure keeps the old baseline for a later retry. With on_invalid: warn, a source that fails to build stays in the old state and is retried. With abort, the apply stops on the failure.
The catalog updates changed sources before removing stale ones. It invalidates cache entries for updated and removed IDs, then wakes requests that were waiting for the catalog.
This diagram shows how a location change becomes a catalog change.
flowchart LR
T[Filesystem event or poll] --> D[Discover current sources]
D --> C[Compare with last good baseline]
C --> B[Build additions and updates]
B --> A[Apply catalog changes]
A --> I[Invalidate changed source cache]
A --> S[Serve the new catalog]
References: crates/…/reconcile.rs• L13-37 crates/…/reconcile.rs• L54-158 crates/…/reload.rs• L86-185 crates/…/tile_source_manager.rs• L159-248
Change checklist
When these files or sections are changed, remember to consider these:
- Keep accepted YAML shapes, generated schema shapes, custom deserializers, and saved configuration aligned when a shared primitive changes.
- Keep command-line fields and file fields aligned so an operator override reaches the expected setting.
- Keep global, source-kind, connection, and per-source precedence identical during startup and reload construction.
- When source IDs or ID templates change, check reserved names, collisions, catalog provenance, and saved configuration output.
- When a source gains a local or remote location, update its location classification, discovery trigger, polling interval, and saved provenance together.
- When version rules change, verify that replacements update while failed discovery retains the last good baseline.
- When object-store options change, preserve credential redaction, proxy URL sanitization, and DuckDB secret mapping.
- When PostgreSQL or DuckDB discovery changes, keep explicit entries, auto-publish scope, source IDs, and catalog reload behavior consistent.
- When COG encoding or expiry settings change, check direct files, mosaics, STAC searches, and tile indexes as separate source forms.
- When style source rules change, keep explicit-file validation separate from directory discovery through
pathsandcollections. - When tiling rules change, keep layer-level operations separate from feature rules and preserve zoom range validation.
- When OpenStreetMap settings change, keep their bulk-only scope separate from live HTTP source configuration.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A plain YAML variable is missing | Configuration parsing stops before source startup | Set the variable or provide a shell-style fallback. |
--config is combined with positional source connections | Argument merging is rejected | Put source declarations in the file or use positional connections without --config. |
| A path uses a location scheme that its source kind does not support | The source is rejected or treated as the wrong location | Check the source kind's local and remote support before changing a path. |
| A source path disappears | Startup fails or a later successful discovery removes the source | Restore the path and select on_invalid: warn when degraded service is acceptable. |
| A remote listing or metadata check fails | The last good remote view remains in the catalog | Restore object-store access; the next poll retries discovery. |
| A changed source cannot be rebuilt | warn keeps the old source and retries; abort stops the apply | Validate source-specific settings and choose the invalid-source policy for the deployment. |
| A source ID collides with a reserved or existing ID | Martin adds a suffix and the public ID changes | Set explicit unique IDs or a non-colliding ID format. |
| A key is misspelled or belongs to no enabled section | Martin warns and ignores it | Check dotted-path warnings against the active configuration section. |
Plain HTTP is used without allow_http | The remote store refuses to open | Use HTTPS or enable plain HTTP only when required. |
| COG format, quality, background, and conversion settings conflict | The COG source fails validation | Match quality and background to the selected format and keep conversion separate. |
| A PostgreSQL source names an unknown or unusable tile grid | The source is rejected or skipped | Define the grid and ensure the source data can be transformed to it. |
A PostgreSQL table mixes layer_id with layers | The table configuration is rejected | Use one layer name or a named layer map, not both. |
| Tiling zoom ranges overlap or are reversed | Configuration stops because the result is ambiguous | Use valid, non-overlapping ranges. |
| A whole-tile setting is placed on a table or rule | Configuration stops with a placement error | Put limits, thinning, and merging on the layer that owns the complete feature set. |
A style directory is listed under styles.sources | Martin ignores the directory as one style | Use styles.paths, styles.collections, or list each JSON file. |
| A PBF entry is expected in the HTTP catalog | The PBF is not served as a live tile source | Use the bulk copy or generation flow. |
| A remote DuckDB GeoParquet source has bad store settings or expired credentials | The DuckDB source cannot create its secret or read data | Check endpoint, signing, profile, and credential refresh settings. |
| A local DuckDB database changes after startup | Its catalog changes are not reflected by live reload | Restart Martin or use explicit source configuration for the required view. |
Key files
| File | Why to read it |
|---|---|
| crates/…/config.rs | Defines the top-level configuration, source groups, tile grids, and invalid-source policy. |
| crates/…/root.rs | Shows how config files, CLI overrides, positional connections, and resource paths are combined. |
| crates/…/parse.rs | Shows YAML loading, environment substitution, and source-located diagnostics. |
| crates/…/lifecycle.rs | Shows finalization, source resolution, precedence, and saved configuration. |
| crates/…/one_or_many.rs | Defines the one-or-many input shape. |
| crates/…/auto_option.rs | Defines auto, disabled, and explicit feature values. |
| crates/…/file_config.rs | Defines shared path, collection, named-source, cache, and location behavior. |
| crates/…/process.rs | Defines layered tile processing and resolved per-source response behavior. |
| crates/…/object_store.rs | Defines remote store options, provider resolution, and safe serialization. |
| crates/…/config.rs | Defines PostgreSQL connection, discovery, grid, cache, and reload settings. |
| crates/…/config_table.rs | Defines table source policy and its relationship to output layers. |
| crates/…/mod.rs | Defines the layer and rule model for configured table tiling. |
| crates/…/config.rs | Defines DuckDB and GeoParquet source variants and shared defaults. |
| crates/…/auto_publish.rs | Defines automatic table and macro discovery choices. |
| crates/…/geoparquet.rs | Defines local and remote GeoParquet locations and source identity. |
| crates/…/cog.rs | Defines COG direct, mosaic, STAC, tile-index, encoding, and expiry settings. |
| crates/…/styles.rs | Defines style discovery and optional server-side rendering settings. |
| crates/…/reloaders.rs | Wires source kinds to their runtime reload drivers. |
| crates/…/reconcile.rs | Defines discovery baselines and successful or failed reload reconciliation. |
| crates/…/trigger.rs | Defines filesystem and polling triggers. |
| crates/…/reload.rs | Defines additions, updates, removals, and source provenance passed to the catalog. |
| crates/…/tile_source_manager.rs | Applies reload changes and invalidates affected catalog caches. |