Enterprise Edition
Maintenance mode
Maintenance mode is an Enterprise module, maintenance. It turns on with OM_ENABLE_ENTERPRISE_MODULES=true; there is no separate flag. While a window is active:
- every module API request returns
503 Service UnavailablewithRetry-After,Cache-Control: no-store,X-Maintenance-Mode: 1and the stable error codeMAINTENANCE_MODE; - every backend, portal and storefront page returns a
503page with no scripts and a same-origin logo by default; - queue workers hold claimed jobs before they run, and the local scheduler skips its ticks;
- each process reports a heartbeat with the gate revision it has adopted and its in-flight work.
Not gated: OPTIONS preflight requests, GET /api/maintenance/status, /api/healthz, /api/docs/*, /api/dev-runtime/*, static assets, and requests with a valid bypass token.
Open and close a window
Deploy the Enterprise-enabled app and run the CLI in that deployment's environment. All web processes, workers, schedulers and CLI invocations must share the same maintenance store. For a deployment with two web processes, one worker and one scheduler:
mercato maintenance on --title "Scheduled maintenance" --message "We are updating the service." --expect-processes web=2,worker=1,scheduler=1 --wait-drain
mercato maintenance status
Replace the counts with your deployment's actual inventory. Wait for a successful drain before starting work. The window stays active after a drain timeout. After the operation succeeds and you verify the result, run mercato maintenance off.
On a standalone app generated by create-mercato-app, use a release containing the Enterprise maintenance module and set OM_ENABLE_ENTERPRISE_MODULES=true before running yarn generate and rebuilding or restarting the app. Run the commands above with yarn mercato from the generated app. With Enterprise disabled, the CLI stays available and the maintenance subcommand explains how to enable the module.
Commands
| Command | What it does | Exit codes |
|---|---|---|
mercato maintenance on [--title] [--message] [--until <iso> | --duration 45m] [--retry-after <s>] [--reason] [--allow-bypass [--bypass-ttl 2h]] [--rotate-bypass] [--expect-processes web=N,worker=M,scheduler=K] [--wait-drain [--drain-timeout 120s]] [--json] | Starts a window, or updates the page fields of the active one without starting a new window. | 0 ok · 2 invalid arguments · 3 drain timed out (the mode stays on) · 4 store unreachable |
mercato maintenance off [--force-release-stale-holds] [--json] | Ends the window. Refuses while an operation holds the window or a reopen barrier is pending. | 0 · 4 · 5 held |
mercato maintenance status [--json] | Shows the state, the source, holds, and each process's acknowledgment and in-flight count. | 0 · 4 |
mercato maintenance drain [--timeout 120s] [--expect-processes ...] [--json] | Waits until every process acknowledges the window with no work in flight. | 0 · 3 · 6 not active |
The commands do not need a database connection. --json output is a versioned object ({ "version": 1, ... }).
State store
The state lives outside the application database, so it survives a restore and works while the database is down.
| Variable | Default | Meaning |
|---|---|---|
OM_MAINTENANCE_STORE | auto | redis when a Redis URL is configured (MAINTENANCE_REDIS_URL, QUEUE_REDIS_URL, CACHE_REDIS_URL or REDIS_URL), otherwise file. |
OM_MAINTENANCE_STATE_DIR | <app>/.mercato/maintenance | File backend directory. The file backend supports a single host only. |
OM_MAINTENANCE_FORCE | off | Forces the mode on without consulting the store. off cannot override it. |
OM_MAINTENANCE_POLL_MS | 2000 | How often each process re-reads the state. |
OM_MAINTENANCE_HEARTBEAT_MS | 5000 | Process heartbeat interval. A process is stale after three missed heartbeats. |
OM_MAINTENANCE_EXPECTED_PROCESSES | unset | Writer inventory, for example web=2,worker=1,scheduler=1. Drained holds require one. |
OM_MAINTENANCE_DRAIN_TIMEOUT_MS | 120000 | How long protected encryption commands wait for the drain. |
OM_MAINTENANCE_REDIS_ASSUME_DURABLE | off | Treat Redis as durable when managed Redis blocks CONFIG GET. Set it only when AOF or RDB persistence is enabled. |
If the store becomes unreachable, processes keep the last state they knew. A process that starts while the store is unreachable serves traffic (fail-open) and logs an error. Protected operations always fail closed.
Customizing the page
In priority order:
--titleand--messagefor the current window. Plain text: it is HTML-escaped, and newlines become paragraphs.OM_MAINTENANCE_PAGE_TEMPLATE=<path to .html>. Placeholders are{{title}},{{message}},{{until}},{{untilIso}},{{retryAfter}},{{supportUrl}},{{logoUrl}}and{{lang}}. Every value is HTML-escaped.- A template is rejected, and the built-in page served, when it:
- contains
<script>, an inline event handler or ajavascript:URL; - puts a placeholder inside
<style>or astyleattribute; - is missing
{{title}}or{{message}}.
- contains
- Inline
<style>blocks are allowed through their SHA-256 hash in the page's own Content-Security-Policy.
- A template is rejected, and the built-in page served, when it:
OM_MAINTENANCE_LOGO_URLandOM_MAINTENANCE_SUPPORT_URL. They accept HTTP(S) URLs and same-origin paths. The default logo is the login asset,/open-mercato.svg. For custom branding, place an asset atpublic/branding/logo.svgand setOM_MAINTENANCE_LOGO_URL=/branding/logo.svg.- The built-in localized defaults.
OM_MAINTENANCE_TIMEZONE(defaultUTC) sets the time zone of the expected end time.
Save a custom layout as an HTML file you own, for example:
<!doctype html>
<html lang="{{lang}}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{title}}</title>
<style>body { font: 1rem system-ui; margin: 3rem auto; max-width: 36rem; padding: 1rem; }</style>
</head>
<body>
<main>
<img src="{{logoUrl}}" width="150" alt="">
<h1>{{title}}</h1>
<p>{{message}}</p>
<time datetime="{{untilIso}}">{{until}}</time>
</main>
</body>
</html>
Set OM_MAINTENANCE_PAGE_TEMPLATE to the absolute path as seen by each web process. Include the file in your deployment or mount it into each replica. Restart the web processes after changing the file because each process caches the template. Put placeholders in text or quoted attributes. Quote notices with --title and --message when opening a window to preview the result.
Bypass
mercato maintenance on --allow-bypass prints a one-time token; the store keeps only its SHA-256 hash.
- Browser: open
/maintenance-bypassand submit the token. You get anHttpOnlyom_maintenance_bypasscookie and a warning banner in the backend. Sign in as usual when prompted. The bypass only lifts the maintenance gate for that browser. - API clients: send
X-Maintenance-Bypass: <token>.
The token is never placed in a URL. It is bound to the window and expires with --bypass-ttl. --rotate-bypass reissues it. A bypass is refused while an operation that forbids it holds the window; every encryption-maintenance hold does.
Encryption key rotation
On an Enterprise install with this module, these commands run only inside an exclusive, drained hold that forbids bypass:
entities rotate-encryption-keyauth rotate-encryption-keyentities decrypt-databaseentities backfill-system-encryption
--dry-run runs (and decrypt-database --check) are exempt. So is entities seed-encryption, which only provisions key maps and runs during mercato init.
- Start a window and wait for the drain:
mercato maintenance on --expect-processes web=2,worker=1,scheduler=1 --wait-drain. You can also pass--enter-maintenanceto the rotation command instead. - Run the rotation. Without a window it refuses with exit 7 and writes nothing. A drain timeout exits 3, and an unreachable or non-durable store exits 4; both also write nothing.
- The window stays on after the command, whether it succeeds or fails. Verify the result, then run
mercato maintenance off.--exit-maintenanceturns the mode off only after a successful run.
decrypt-database --deactivate-maps records a reopen barrier. mercato maintenance off refuses until every writer has restarted after the retirement, so no replica keeps an old policy in memory. There is no flag that skips the maintenance requirement on Enterprise. On OSS installs, or with Enterprise modules disabled, these commands behave as before.
Status endpoint
GET /api/maintenance/status is public and read-only. It returns only { active, until, retryAfter, message }. Backend pages poll it every 30 seconds. If a window starts while a page is open, a blocking overlay explains why saves fail and offers a reload.