Skip to content

10. Reference

Derived from internal/cli, internal/initctl, internal/api, internal/spec, internal/compose, internal/registry and templates/control/docker-compose.yml (all under packages/pstack).

pstack <up|down|verify|status|validate|init|serve|swarm|…> [flags]
Command Does Exits
up assert every requires first, then provision axes in declaration order (each up, then its assert_live), then compose up -d --remove-orphans with the selected profiles. Fails fast — stops at the first failure. 0 · 1
down compose down -v --remove-orphans with all profiles → each axis’s down in reverse order (best-effort, never fatal) → verify unless --no-verify. Refused on kind: shared without --force (exit 1). 0 · 1 · 2
verify run every assert_gone. Axes without one are reported unverifiable, not passed. 0 · 2
status compose ps for this stack, passed through 0
validate parse, resolve interpolation, list axes and hooks, print warnings. Touches nothing. 0 · 3
init stand up the control stack (pstack-control: Traefik + the API/UI) on this host. Idempotent. Preconditions → dirs → networks → config → compose up -d → wait for the healthcheck. Never an HTTP route. 0 · 1 · 3
serve HTTP API + UI over the deployment registry. Runs until killed. 3 on refusal
swarm [status] the swarm’s nodes, the manager address and the ports a worker needs. Read-only; reads docker every time. Exit 1 when this host is not a manager, so a script need not parse it. 0 · 1
swarm join what a new worker runs — --format command (default), script, cloud-config (+--distro) or token. The output is a secret: every shape embeds the join token. To stdout, or -o <file>. 0 · 1 · 3
api <group> <command> call any API route. Generated from api/openapi.yaml; --help at any level lists what is under it. Needs PSTACK_API_URL and PSTACK_TOKEN. Non-2xx exits non-zero 0 · 1
route ls|create|assign|unassign|rm list and point custom routes: a stable name for whichever stack it is assigned to. Talks to PSTACK_API_URL; a held route exits 1 naming its holder and --force. 0 · 1 · 3
pull config seal this host’s whole portable configuration — accounts, tokens, host secrets, notifiers, SSO, registry logins, routing files, named specs — into one 0600 file (-o, never stdout). Talks to PSTACK_API_URL as the root token. 0 · 1 · 3
push config apply such a file onto the host at PSTACK_API_URL. Creates, never overwrites; names every registry and notifier URL it would trust and asks first (-y to skip the question and the list). Not transactional — a failure leaves what it already wrote. 0 · 1 · 3
forward [set <url>|off] where the host at PSTACK_API_URL forwards its deploys and unserved visitors. set checks the target first and needs PSTACK_FORWARD_TOKEN; set and off need an admin. 0 · 1 · 3
migrate copy deployments from --from to --to and match each one’s state there; --sleep-source is a sleep pass: no copy, sleeps the source copies the target holds. Never down. Exit 1 when any failed; a re-run catches up. 0 · 1 · 3
scaler the worker scaler daemon, run by the control stack’s scaler container (init --scaler on). Configured by environment only. Runs until SIGTERM, finishing a running Tofu command first. Exit 1 when another pstack scaler holds the state directory or OpenTofu cannot be installed; 3 without PSTACK_TOKEN. 0 · 1 · 3

init, serve, swarm, route, pull/push, forward, migrate and scaler are spec-free: they act on the host and on the registry, so none of them loads preview.yml or fails because it is absent.

Every teardown step is recorded non-fatally, so down in practice returns 0 or 2 — a failed assert_gone is the only thing that moves the needle. The two ways it still returns 1: the kind: shared refusal (nothing ran at all), and an unhandled crash.

Flag Applies to Effect
-f, --file <path> all but init serve spec file. Default preview.yml.
-n, --dry-run up down verify init print each step, execute nothing. Prints step labels, not shell commands. A green dry-run proves ordering, never absence — requires asserts and init’s preconditions are skipped and report ok, so init -n says nothing about whether Docker or the control image exist.
-v, --verbose all echo each command as $ <cmd> plus its stdout/stderr, indented |. Ignored under --dry-run.
-q, --quiet all narrower than it sounds: on its own it suppresses only the stack: … header. Step lines (→ …) and the final report always print. Combined with -n it also drops the [dry-run] lines.
--set K=V all define/override a spec variable; repeatable. Wins over the ambient environment, but a key the spec’s own env: defines still wins over --set.
--no-verify down skip the post-teardown leak check. Turns a leak into exit 0.
--force down allow tearing down a kind: shared deployment. Nothing else lifts that guard, and the HTTP API never passes it.
--domain <apex> init required (or PSTACK_DOMAIN). Every hostname is derived from it.
--acme-email <addr> init required (or PSTACK_ACME_EMAIL).
--challenge http01|dns01 init default http01 (or PSTACK_CHALLENGE). Any other value exits 3.
--dns-provider <lego-code> init required for dns01 only (or PSTACK_DNS_PROVIDER); ignored by http01.
--orchestrator swarm|compose init cloud-init upgrade default swarm for init/cloud-init (or PSTACK_ORCHESTRATOR); upgrade keeps the host’s current one unless the flag is typed.
--logging none|loki init cloud-init default none (or PSTACK_LOGGING). loki runs Loki in the control stack and ships every deployed service’s logs to it; cloud-init passes it to init. Any other value exits 3.
--scaler on|off init cloud-init default off (or PSTACK_SCALER). on adds the worker scaler to the control stack. Swarm only: with --orchestrator compose it exits 3. upgrade keeps it; an init that would drop it is refused unless --scaler off is typed.
--previews-on workers|any init cloud-init swarm only: where previews may run. Not an enum value exits 3; with --orchestrator compose it exits 3 too. See Keeping the manager for the control stack.
--ingress-subnet <cidr> --shared-subnet <cidr> init swarm only: the two networks’ ranges, 10.250.0.0/16 and 10.251.0.0/16 by default. Unset keeps an existing network; set and different re-creates it. Not an IPv4 range exits 3.
--format <shape> swarm join command (default), script, cloud-config or token. An unknown one exits 3.
--distro <name> cloud-init swarm join which Docker install steps the rendered cloud-config uses: ubuntu debian fedora suse arch alpine. Ignored by the other formats.
-o, --out <file> cloud-init swarm join pull config write the rendered file instead of printing it. Required for pull config, which never writes an export to stdout and creates the file 0600.
-i, --in <file> push config the sealed export to apply. Required — there is no stdin form.
--via <ip[:port]> forward set where to connect; the URL’s host stays the Host header and TLS name. For a URL that still resolves to this host (7f).
--from <API URL> --to <API URL> migrate the source and target hosts. Both required.
--sleep-source migrate a sleep pass: no copy, no change on the target; sleep each running source copy the target holds. Never down.
--admin-user <name> cloud-init the first UI account, created on first boot. Prompted when absent unless -y. Its password comes from --admin-password, or is generated and printed beside the username
--admin-password <pw> cloud-init that account’s password. Refused without --admin-user. Never prompted — an absent one is generated, so the value exists nowhere else and can be discarded after the first sign-in
--api-token <token> cloud-init PSTACK_TOKEN, written into the rendered file. Omitting it is preferred: init then mints one on the host and prints it once into the boot log, keeping it out of instance metadata
--config <file> cloud-init embed a sealed export in the rendered file, applied on first boot. The passphrase is embedded too, so both sit in instance metadata.
--config-url <url> cloud-init fetch the export at boot instead, so only the passphrase is embedded. Mutually exclusive with --config.
-y cloud-init push config never prompt. On push config it also replaces the list of registries and notifier URLs with a count — those strings are credentials, and a log is not a terminal.
-h, --help — usage, exit 0

An unknown flag, an unknown command, no command, a malformed --set, a bad --challenge, a missing --domain/--acme-email, or dns01 without a provider all exit 3.

Code Name Meaning
0 ok operation succeeded; nothing checkable leaked
1 failed an operation errored — up hook, assert_live, compose up
2 leaked teardown ran but assert_gone says something survived, or could not be proven gone
3 usage bad spec, bad flag, missing variable, spec not found, serve refusing to bind

2 is distinct from 1 on purpose: “torn down but something survived” and “teardown errored” are different problems with different owners.

Variable Used by Default Meaning
PSTACK_TOKEN serve init scaler unset / generated bearer token for mutating routes. Required to bind off-loopback. init generates one when unset and prints it once. scaler needs it: it calls the API as root.
PSTACK_PORT serve 7878 listen port
PSTACK_API_URL pull config push config forward — which pstack to talk to, e.g. https://api.preview.example.com. No default on purpose — a guess would silently talk to the wrong host. Plain http:// is refused unless the host is loopback or a private address.
PSTACK_API_URL scaler http://pstack:7878 where the scaler reaches pstack; the control stack sets it. Env-only, like serve’s tuning.
PSTACK_SCALER_STATE scaler /state the scaler’s state directory: OpenTofu, Tofu state, scaler.json. Locked, so a second pstack scaler on it exits 1. Env-only.
PSTACK_FORWARD_TOKEN forward set — a user token on the target, developer or higher, never its root token. Flag-less on purpose.
PSTACK_FROM_TOKEN · PSTACK_TO_TOKEN migrate — a token on the source; a token on the target. Flag-less on purpose.
PSTACK_CONFIG_KEY pull config push config cloud-init prompted the passphrase the export is sealed with. Prompted without echo when unset and on a terminal; flag-less on purpose, because argv is world-readable through ps.
PSTACK_HOST serve 127.0.0.1 listen address. Forced to 127.0.0.1 without a token; a non-loopback value without a token is refused with exit 3.
PSTACK_DATA serve init /var/lib/pstack registry + control-stack config root. The registry lives at <PSTACK_DATA>/deployments.
PSTACK_DOMAIN init — same as --domain
PSTACK_ACME_EMAIL init — same as --acme-email
PSTACK_CHALLENGE init http01 same as --challenge
PSTACK_DNS_PROVIDER init — same as --dns-provider
PSTACK_DNS_TOKEN init unset the DNS-01 credential; written to control/dns.env (0600) under the provider’s own variable name. Flag-less on purpose — a secret does not belong in a shell history.
PSTACK_IMAGE init pstack:local the control-stack image
PSTACK_ORCHESTRATOR serve init compose / swarm serve: the default for a spec that does not say (compose); init: same as --orchestrator (swarm). The control stack sets it for the API from what init decided.
PSTACK_LOGGING init cloud-init none same as --logging
PSTACK_NO_OOM_PROTECT init unset any value but 0 skips protecting dockerd from the OOM killer (below). For a host that manages docker.service itself
PSTACK_AGENT_IMAGE init docker:29.9.2-cli the image pstack-agent runs in on every node. Not read back: re-export it on every init and upgrade, or the agent returns to the default. Cloud-init does not pass it
PSTACK_PREVIEWS_ON init cloud-init unset same as --previews-on
PSTACK_SCALER init cloud-init off same as --scaler
PSTACK_INGRESS_SUBNET PSTACK_SHARED_SUBNET init (and upgrade, which runs it) unset same as --ingress-subnet / --shared-subnet. Set on pstack upgrade, it reaches the init the upgrade runs — the one-command way to enlarge an existing host’s network
PSTACK_LOKI_PASSWORD init generated the Loki push password under --logging loki; written to control/.env as LOKI_PUSH_PASSWORD. Flag-less on purpose.
PSTACK_DOMAIN serve — lets the API build absolute share-link URLs on control.<domain>. Set by the control stack.
PSTACK_PROBE serve on off removes GET /api/probe/:id, the unauthenticated probe; the path then 404s like any unknown one. Any other value, including a misspelling, leaves it on — a typo should not silently turn a CI pipeline into one that polls a 404 forever
PSTACK_MAX_JOBS serve 4 lifecycle jobs running at once, across every stack. The default for the max_jobs setting, not the authority (0.33.0): a value stored through PUT /api/settings/max_jobs outranks it and survives a restart, so setting it here is how a host that never opens the UI is configured — see Runtime settings.
PSTACK_STATS_TICK_MS serve 30000 how often the node agents’ logs are read and pressure judged. 0 turns the loop off, and with it every pressure guard and prune — see Node pressure
PSTACK_TRAEFIK_METRICS serve — Traefik’s Prometheus endpoint, what sleep.idle reads. http://traefik:8082/metrics inside the control stack; unset means idle never triggers.
PSTACK_READINESS_POLL_MS · PSTACK_READINESS_TIMEOUT_MS serve 2000 · 180000 how often the readiness watcher re-reads docker, and how long before it calls a stack timed out. Tuning for a test harness driving serve black-box; a host never needs them.
PSTACK_READINESS_RESTART_LOOP serve 3 restarts tolerated before the readiness watcher calls a container a crash loop. Unlike the two above, this is operator-facing: raise it on a swarm host — swarm has no depends_on, so a dependent service legitimately restarts a few times while its database converges.
PSTACK_SSO_STATE_TTL_S · PSTACK_SSO_DISCOVERY_TTL_S serve 300 · 3600 how long a half-finished SSO sign-in is remembered, and how long a provider’s discovery document and JWKS are trusted. Same audience.
PSTACK_LOKI_DIR serve /etc/loki if mounted, else <PSTACK_DATA>/control/loki Loki’s config.yaml and s3-credentials, written by Loki settings.
PSTACK_LOKI_READY_TIMEOUT_MS serve 300000 how long a Loki settings apply waits for Loki to be ready. Test harness tuning; a host never needs it.
PSTACK_LOKI_UID serve 10001 owner of s3-credentials, so Loki can read it. 0 reads as unset.
PSTACK_PORT healthcheck 7878 the port pstack healthcheck probes — the container HEALTHCHECK, exit 0 or 1 on GET /api/health.
PSTACK_BINARY build-image unset — the image installs this version from its release path to a pstack binary to copy into the control image instead, for a version that is not published yet or a host with no network at build time.
PSTACK_VERSION · PSTACK_INSTALL_DIR install.sh the script’s release · /usr/local/bin pin the version the installer fetches; where it puts the binary. pstack upgrade sets both.

serve needs no spec and no stack variable to start.

Seven host knobs are changeable while the server runs, without restarting the control container. They live in the database, and the list is closed — this is not a general key-value store, and a key nobody named is refused rather than stored.

Key Value Read Write What it decides
max_jobs whole number ≥ 1 viewer maintainer how many lifecycle jobs run at once across every stack. In force on the request that sets it — the registry takes the new cap immediately
default_role one of viewer, developer, maintainer, admin viewer admin the role an account created with no role named gets: POST /api/users without one, and any SSO provider whose own defaultRole is empty
pressure_disk_pct whole number 0–100, default 90 viewer admin disk used % that puts a node in pressure. 0 is off
pressure_mem_pct whole number 0–100, default 10 viewer admin memory free % (MemAvailable) at or below which a node is in pressure. 0 is off
pressure_cpu_load number ≥ 0, default 2 viewer admin 5-minute load per core that puts a node in pressure. 0 is off
pressure_sleep_idle_min whole number 0–525600, default 30 viewer admin how long a stack must be unused before pressure may sleep it. 0 turns auto-sleep off
image_prune_after_h whole number 0–87600, default 168 viewer admin age in hours of the unused images and build cache the 6-hourly prune removes. 0 turns it off

Precedence: database > environment > built-in default. A stored value wins; without one the environment variable is used; without that, what the binary ships with. PSTACK_MAX_JOBS is therefore the default for max_jobs, not the authority — a host whose operator never opens the UI behaves exactly as it always did, and one who sets the value here is not overridden on the next restart. default_role and the five pressure keys have no environment variable at all: each is its default until somebody sets it.

Which layer won is readable, because a box that says 4 when you typed 8 is otherwise unexplainable:

Terminal window
curl -s https://api.preview.example.com/api/settings -H "Authorization: Bearer $PSTACK_TOKEN"
{
"settings": [
{ "key": "max_jobs", "value": 4, "source": "default", "minRole": "maintainer" },
{ "key": "default_role", "value": "viewer", "source": "default", "minRole": "admin" },
{ "key": "pressure_disk_pct", "value": 90, "source": "default", "minRole": "admin" },
{ "key": "pressure_mem_pct", "value": 10, "source": "default", "minRole": "admin" },
{ "key": "pressure_cpu_load", "value": 2, "source": "default", "minRole": "admin" },
{ "key": "pressure_sleep_idle_min", "value": 30, "source": "default", "minRole": "admin" },
{ "key": "image_prune_after_h", "value": 168, "source": "default", "minRole": "admin" }
],
"env": { "PSTACK_MAX_JOBS": null },
"precedence": "database > environment > built-in default"
}

source is db, env or default; env reports what this process was started with (null when nothing usable was set), so an override you cannot see from the UI is still visible in the answer. minRole comes from the permission table itself, so it cannot drift from what the route enforces.

Terminal window
curl -sS -X PUT https://api.preview.example.com/api/settings/max_jobs \
-H "Authorization: Bearer $PSTACK_TOKEN" -H 'content-type: application/json' \
-d '{"value": 8}'

A write answers with the row it stored, "stored": true, and — for max_jobs — a note repeating what lowering the cap does not do. Lowering it kills nothing: jobs already running run to completion and the new cap applies to the next dispatch. A refused value is a 400 naming the key.

Storing a value is a decision to stop following the environment, and there is no API to undo it. PUT is the only write these keys have — there is no DELETE, and an empty value is refused — so a host that has stored a max_jobs goes back to obeying PSTACK_MAX_JOBS only by removing the row itself (DELETE FROM settings WHERE key = 'max_jobs' against <PSTACK_DATA>/db/pstack.db, with the control container stopped). Changing your mind about the value is a second PUT; changing your mind about the layer is not something the API does.

The tiers are different on purpose. max_jobs is operational and sits with the rest of the host’s configuration, at maintainer. default_role is user management by another name — it decides what every account created without an explicit role can reach — so it sits with the promotion paths, at admin. It never widens what the caller may do: creating accounts is already admin-only, and POST /api/auth/bootstrap is deliberately unaffected (the first account on a host is an admin because there is nobody to promote it).

:id is a registry id (e.g. pr-123), never the resolved stack name. Every route requires a principal — reads included, since 0.10.0 — except /api/health, the login/bootstrap routes and the two SSO legs, which are how you become one, and Grafana’s two sign-in routes (Grafana). A session cookie is what lets the log stream use EventSource, which cannot send headers. Since 0.31.0 a principal is not enough on its own: each route also names a least role — 7e is the matrix, and anything it does not list is the root token’s alone.

Method Route Body / query Returns
GET /api/health — { ok, authEnforced, hasUsers, sso, dataDir, version, grafana? } — sso is { providers: [{ key, label, preset }…] } (enabled providers, in key order) or null, read by the login page before authenticating; grafana is https://grafana.<domain>, present only on a host running Grafana
GET /api/deployments spec variables as ?K=V, optional { deployments: [{ …meta, stack, busy, running, unresolved? }] }. A row whose variables were not supplied degrades to stack: null + unresolved: <reason> rather than failing the listing; busy/running are null when undeterminable
GET /api/openapi.yaml · /api/openapi.json — No token. The API’s own OpenAPI document — the same file pstack api is generated from. YAML is the file byte for byte (comments and key order intact); JSON is that file, key order preserved. ETag is the version
GET /api/probe/:id — No token. The upstream’s own status, no body ever, and x-pstack-probe: upstream|unknown|asleep|no-target|unresolved|unreachable|busy. ?service= names which one on a stack that publishes several. See Probe a preview without a token
GET /api/deployments/:id spec variables as ?K=V, required { id, kind, createdAt, updatedAt, stack, busy, compose, requires, axes[{name,hooks}] } — hook names, never bodies
PUT /api/deployments/:id { spec, compose?, env? } — body only, the query string is not read here { id, kind, stack, createdAt, updatedAt }, plus swarmNotes under swarm — what the conversion will change, named at submit time rather than in the deploy transcript. Omitted, never [], when nothing was checked · 201 new · 200 replaced · 400 bad spec/body · 409 while a job is in flight. The spec is parsed before it is stored, so its variables must be in the body’s env or the submit is a 400
DELETE /api/deployments/:id spec variables as ?K=V forget it. Refused while containers exist and when Docker did not answer
POST /api/deployments/:id/up spec variables as ?K=V 202 { job } — state: "queued" when the stack is busy
POST /api/deployments/:id/down { verify?, force?, forget? } (verify defaults true) 202 { job } — preempts: cancels what is running, drops what is queued · 409 on kind: shared without force · forget: true also forgets the deployment in the same job, only if the teardown finished clean (no failed step, no leak, no container left); 400 with verify: false
POST /api/deployments/:id/verify spec variables as ?K=V 202 { job } — state: "queued" when the stack is busy
POST /api/deployments/:id/sleep spec variables as ?K=V 202 { job } — queued when busy · 409 on kind: shared · 400 without a compose section. Compose project down, volumes and axes kept
POST /api/deployments/:id/wake spec variables as ?K=V 202 { job } — up, recorded as a wake
POST /api/deployments/:id/cancel — 200 { cancelled: [job…], by, warning } — stops the running job AND the queued one. cancelled is [], never null. The warning appears only when something had actually started
GET /api/config — the whole portable configuration in plaintext: password hashes, token hashes, host secrets, notifier secrets, the SSO client secrets, registry logins. Root token only — an admin session or personal token is 403. cache-control: no-store. Emits config.exported
POST /api/config that document applies it create-or-skip → { trusts, created, skipped } · 400 on a document this build does not understand · 403 for anything but the root token · 413 over 8 MiB. Emits config.imported, including when it fails part-way
GET /api/settings — { settings: [{ key, value, source, minRole }…], env, precedence } — the seven runtime settings, resolved, each saying which layer it came from. viewer. See Runtime settings
PUT /api/settings/max_jobs { value } the row + stored + a note. maintainer. In force immediately — no restart; lowering it cancels nothing already running · 400 on anything but a whole number ≥ 1
PUT /api/settings/default_role { value } the row + stored. admin — it decides the role of accounts created without one · 400 on an unknown role
PUT /api/settings/pressure_disk_pct · pressure_mem_pct · pressure_cpu_load · pressure_sleep_idle_min · image_prune_after_h { value } the row + stored. admin. Read on the next stats tick · 400 outside the key’s range (Runtime settings)
POST /api/users { username, password, email?, role? } 201 { user }. Admin only (0.31.0), and an absent role means the host’s default_role setting — viewer until somebody sets one. This route honours admin if that is the host default, unlike an inheriting SSO provider which is capped below it: creating accounts is already admin-only, so an admin minting at a level they chose is exercising authority they have, not a stranger acquiring it. See 7e. An unknown role is a 400. The optional email is what lets an SSO login adopt this account instead of creating a second one
PATCH /api/users/:id { role } { updated, role } · admin only · 400 on an unknown role or on demoting the last admin · 404. Takes effect on that account’s next request
DELETE /api/users/:id — { deleted } · admin only · 400 on the last user or the last admin · 404
PUT /api/users/:id/password { password } { ok, revokedSessions } — your own at any role, anybody else’s is admin. Revokes that account’s sessions and personal tokens
POST /api/deployments/:id/share { views?: ["details","logs"], ttl?: "7d" } 201 { url, token, views, expiresAt } — a read-only link; 400 with no PSTACK_TOKEN to sign with, or a ttl over 30d
GET /api/auth/sso/start ?provider=<key>&next=<same-origin path> 302 to that provider, with PKCE. Keyless: one enabled provider is picked, several land on /login?sso_error=… naming the keys, none says so too. No auth — this is how you sign in
GET /api/auth/sso/callback ?code=&state= (the provider’s redirect) 302 with a session cookie, or 302 to /login?sso_error=… — completed against the provider the state was minted for. No auth
GET /api/auth/grafana/verify Traefik’s X-Forwarded-Uri/-Method/-Host, the browser’s cookies 204 with X-WEBAUTH-USER/X-WEBAUTH-ROLE · 302 to sign-in, or from /-/pstack/callback back to Grafana with the Grafana cookie · 401 a fetch or frame with no Grafana cookie · 403 No Grafana access. or Cross-origin request refused. · 404 on a host without Grafana. Traefik’s forwardAuth for grafana.<domain>. No auth
GET /api/auth/grafana/start ?state=&next= 302 to Grafana’s callback with a 60-second code, or to /login?next=… when signed out · 400 Sign-in link is invalid. · 404 on a host without Grafana. A 302 for a browser. No auth
GET /api/sso/config — { providers: [{ key, config, secretSet, updatedAt }…], callbackUrl, presets[] } — the secret has no read path, a read learns secretSet and nothing else
PUT /api/sso/config { key, …config, clientSecret } { ok, key, config, callbackUrl } · 400 on a bad field, an unreachable issuer, or a keyless body when several providers exist. Submitting the mask keeps that key’s stored secret
DELETE /api/sso/config · /api/sso/config/<key> — forget that provider; the accounts it created stay · bare with several providers is 400 naming the keys · 404 if none
GET /api/swarm — { reachable, active, nodeId, managerAddr, nodes[], ports[], note } — never the join token
GET /api/stats — { v, at, agent, nodes[], stacks[], prune } — what every node’s pstack-agent last reported, an hour of history, and the last prune. Unknown is null. Reads emit nothing (Node pressure)
GET /api/signals — { swarm, reachable, nodes[], stuck[] } — what the cluster looks like now, for whatever adds and removes machines (§7b)
POST /api/swarm/nodes/:id/drain — maintainer and up — stop placing work on a node and move what is there
POST /api/swarm/nodes/:id/undrain — maintainer and up — put it back
DELETE /api/swarm/nodes/:id — maintainer and up — forget a node whose machine is gone; 409 unless docker reports it down and drained
GET /api/swarm/join ?format=token|command|script|cloud-config[&distro=] text/plain, maintainer and up (it was admin before 0.31.0); 409 when this daemon is not a manager
GET /api/control — the control stack’s summary { project, reachable, services[], note } — the dashboard’s card
GET /api/control/runtime — maintainer and up — the operator view: per container, restartCount, oomKilled, memLimitBytes beside the usual state (why)
POST /api/control/restart { service } maintainer and up — restart one control service; pstack itself is always 400 (it is the container answering); 404 unknown service; 503 docker down
GET /api/domains — maintainer and up — { primary, domains[], mode, note }; the list is derived from the routers it wrote
PUT /api/domains { domains } maintainer and up — replace the additional domains; each gets control./api./wake routers. The primary is refused (400)
GET /api/custom-routes — [{ name, deployment, stack, hosts[], blocked[], createdAt, updatedAt }], by name; blocked is [{ host, by: { kind, name } }], the hosts a deployment or an earlier route serves instead; deployment and stack are null when unassigned (custom routes)
POST /api/custom-routes { name, deployment?, force? } developer and up — 201 the route · 400 a bad or reserved name · 409 the name exists or is a stack’s, or a host or router another serves · 404 unknown deployment. force is accepted and ignored: a new route is never held
DELETE /api/custom-routes/:name — developer and up — { deleted }; its routers go · 404
PUT /api/custom-routes/:name/assignment { deployment, force? } developer and up — the route; the same deployment is a no-op 200 · 409 { error, assignedTo: { deployment, stack } } when another holds it, unless force (one move) · 409 a host or router another serves · 404 unknown route or deployment
DELETE /api/custom-routes/:name/assignment — developer and up — the route, unassigned; always allowed · 404
GET /api/tls — maintainer and up — { mode, traefik, wildcard, note }; the mode is derived from the artifacts, never stored
PUT /api/tls/wildcard { cert, key } admin — store a wildcard pair, enter dns-persist-01; 400 names what is wrong with the pair. The key has no read path
DELETE /api/tls/wildcard — admin — back to Traefik-native resolution; 404 when none is stored
POST /api/tls/redeploy — maintainer and up — redeploy every awake stack so labels regenerate; asleep stacks are skipped (labels regenerate on wake), and so are stacks docker does not list (not running; their next up stamps the labels); { started[], skipped[] }
GET /deployments/:id/public-logs-view ?token=<jwt> the page a share link opens (no auth — the token is on the page’s own API calls)
ANY <preview hostname>/* the Host header, via the catch-all router a sleeping or waking stack’s hostname: 503 + Retry-After: 5 + x-pstack-wake: 1 + the wake page. A sleeping one also starts a wake job; a waking one is held until readiness settles (7b). While forwarding, checked first: passed to the target with its Host unchanged, never woken here; a failure is the Down page, 503 + retry-after: 5 (7f)
GET /api/jobs — { jobs: [...] }, newest first, max 50, in-memory
GET /api/jobs/:jobId — { job } · 404
GET /api/jobs/:jobId/stream — SSE: buffered log replay, then live, then {done:true,state}
GET /api/forward — maintainer and up — { to, via, establishedAt, lastOkAt } or null. Never the token
PUT /api/forward { to, via?, token } admin — checks the target first (7f), then the same view · 400 naming the failed check, nothing saved. Emits forward.changed
DELETE /api/forward — admin — { deleted: true }; stop forwarding. Emits forward.changed when there was a setting
GET /api/scaler — maintainer and up — { settings, credentials, report, enabled } (7g). settings is { preset, vars, min, max, cooldownMin, graceMin, dismissed }; credentials is { KEY: true }, never a value; report is the scaler’s last ({ at, hostId, workers[], locked, lastAction, lastError, nextRetryAt, doesNotFit[], orphans[], pendingDestroy }) or null; enabled is true/false/null (the container runs / does not / docker did not answer)
PUT /api/scaler { preset, vars, min, max, cooldownMin, graceMin, dismissed?, credentials? } admin — replaces the settings, then the same view. A credential sent empty, omitted or as the mask keeps its value; null deletes it · 400 preset required, an unknown preset or variable, want 0 ≤ min ≤ max, cooldownMin and graceMin must be ≥ 0, a credential name that is not an environment variable name, a dismissed name that is not a possible orphan · 409 another preset or a changed shared variable while the scaler owns workers; deleting a credential during a preset switch, while it owns workers, or while an old preset’s destroy is pending
GET /api/scaler/presets — maintainer and up — [{ name, builtin, preset, locked }]; preset is { perWorker[], shared[], distro, hash, lockFile }
GET /api/scaler/presets/:name — maintainer and up — the same plus files · 404
PUT /api/scaler/presets/:name { files: { "main.tf": "…" } } admin — store a custom preset, then the preset · 400 a bad name, a built-in’s name, a bad file name, no workers variable, a backend or cloud block · 409 the locked preset with other files
DELETE /api/scaler/presets/:name — admin — { deleted: true } · 400 a built-in · 409 locked, or the selected preset · 404
GET /api/scaler/config — root token only — { preset, vars, min, max, cooldownMin, graceMin, dismissed, credentials, files }: credential values and the selected preset’s files, for the scaler. An admin session or personal token is 403
POST /api/scaler/report the scaler’s report, optionally with one event root token only — { ok: true }. Keeps the owned workers and the locked config for the 409s above, the rest in memory; emits the event (scaler.created, scaler.removed or scaler.failed)
GET / and any non-/api/ path — the embedded single-page UI. No filesystem lookup, so a deep link renders rather than 404s

Status codes: 202 accepted · 400 bad spec or missing variable · 401 unauthorized · 403 a credential the route admits, doing something it may not — a role below the route’s least one (the body names both), a share link outside its views, or an admin at /api/config or the scaler’s two root-only routes · 404 unknown deployment/job · 405 wrong method on an action · 409 job in flight for that stack, or a kind: shared down without force · 500 unexpected.

While forwarding is on, every /api/deployments… and /api/jobs… route above is the target’s, answered as the target answers it, after this host’s own role check. A job this host holds and a share link’s requests stay here. 502 is this host failing to reach the target.

Job state: queued · running · ok · failed · leaked · cancelled · superseded — the seven, of which only the first two are not final. Job action: up · down · verify · sleep · wake.

Hostname Router Serves
control.<domain> pstack-ui the web UI
api.<domain> pstack-api the API
loki.<domain> pstack-loki Loki’s push path, only with --logging loki
grafana.<domain> pstack-grafana Grafana (--logging loki), signed in with pstack accounts; reserved even with logging off

control. and api. point at the same container on port 7878; the UI calls /api/… relatively, so it is same-origin and needs no CORS. loki. is the Loki container on 3100. Under dns01 the pstack-ui router is the one router carrying tls.domains[0].main + .sans — the wildcard every other router inherits by SNI.

version: 1 # required, must be 1
kind: isolated # optional; `isolated` (default) or `shared`
stack: pr-${PR} # required — identity; must match /^[a-z0-9][a-z0-9_-]*$/
env: # optional; interpolated in order, later entries may use earlier
PREVIEW_DOMAIN: preview.example.com
IMAGE_TAG: ${GIT_SHA}
compose: # optional
file: docker-compose.preview.yml # required within `compose`
profiles: [backend, frontend] # up: these · down: ALL of them
overlays: [docker-compose.tls.yml] # extra -f files, applied in order after `file`
orchestrator: swarm # optional; `swarm` or `compose`. Default: PSTACK_ORCHESTRATOR, else compose
sleep: # optional; the scheduler puts the compose project to sleep (volumes + axes stay)
idle: 2h # no request through Traefik for this long
after: 3d # this long after the last deploy, unconditionally
requires: # optional; asserted BEFORE anything is created, in order
- name: shared-db # required — what the failure is reported as
assert: <shell> # required; exit 0 ⇒ the precondition holds
hint: <text> # optional; shown on failure — say how to fix it
axes: # optional; up in order, down in REVERSE
- name: database # required, unique
up: <shell> # provision, idempotent, fatal on failure
assert_live: <shell> # exit 0 ⇒ exists; fatal on failure
down: <shell> # destroy; best-effort, never fatal
assert_gone: <shell> # exit 0 ⇒ gone; fatal for verify (exit 2)
Rule Detail
kind: shared a host singleton. May declare no axes — a hard error, not a warning. down is refused unless --force, and the HTTP API never passes force, so it cannot be torn down over HTTP at all.
kind: isolated the default. With no axes you get a warning: nothing per-tenant is provisioned or verified, so it is just a Compose project.
compose.orchestrator compose or swarm; anything else is an error. Resolution: the spec, then PSTACK_ORCHESTRATOR, then compose. Under swarm the file is converted on every invocation — see Swarm mode.
sleep a mapping with idle and/or after (durations 90s 30m 2h 3d 1h30m); anything else is an error, and an empty block is too. Never honoured on kind: shared. Without a compose: section it is a warning — there is nothing to put to sleep.
requires every assert runs before the first axis, in declaration order; the first failure aborts up with exit 1 and nothing has been created. hint is appended to the failure message.
interpolation ${VAR} only, resolved once at parse time, so a value containing ${…} is never re-expanded
precedence spec env: wins over --set, which wins over the ambient environment. --set cannot override a key the spec’s env: also defines — that is a spec edit, not a CLI override.
undefined variable hard error, exit 3. Empty string counts as undefined.
resolution order env: entries (in declaration order, each able to use earlier ones) → stack: → compose.* → axis hooks
${STACK} in the spec available in compose.* and axis hooks, not in env: — env: is resolved before stack: is. env: X: ${STACK} fails with undefined variable(s) ${STACK}.
$STACK in a hook always exported at runtime, so $STACK and ${STACK} both work inside a hook body
hook environment resolved spec env + STACK + everything captured from earlier up hooks
KEY=VALUE capture SHOUT_CASE lines on an up hook’s stdout become env vars for compose and later hooks
empty axis an axis with none of the four hooks is an error
duplicate axis name error
stack name must match /^[a-z0-9][a-z0-9_-]*$/ — it becomes a Compose project name, a hostname label and usually a namespace id
shell every hook runs via bash -c. Not a sandbox — treat the spec at CI trust level.

All non-fatal; validate still exits 0. Each one is a way an axis can lie to you.

Warning Trigger Fix
kind: isolated with no axes an isolated spec that has a compose: block and no axes add the axes it needs, or mark it kind: shared if it is a host singleton so down is guarded
has up but no assert_gone an axis defines up and no assert_gone add a probe, or accept a permanent ? in every report
assert_gone is a bare ! <probe> a single-line assert_gone starting with ! and containing no exit, || or && guard it: <probe-is-usable> || exit 1, then ! <probe> on the next line
assert_gone contains || true || true anywhere in the assert_gone script remove it; tolerate failure in down, never in an assert
Location $PSTACK_DATA/deployments/<id>/ — PSTACK_DATA defaults to /var/lib/pstack
Files spec.yml · compose.yml (when submitted) · meta.json ({ id, kind, createdAt, updatedAt })
Id charset /^[a-z0-9][a-z0-9._-]{0,63}$/, no .. — ids become directory names and reach shell hooks
put validates before committing; rm -rfs the directory and throws RegistryError if the spec is rejected. kind is read from the parsed spec, never from the caller.
remove forgets only, never tears down. Callers must down first — removing the record while containers run orphans them beyond the control plane’s view.
Why files it is a cache of intent; truth is Docker + each axis’s assert_*. Losing it is recoverable by re-submitting, and a directory of YAML is greppable and diffable.
Rule Why
down passes every profile in the spec Compose treats a non-enabled profile’s services as absent, so a narrower down leaves that profile’s resources — visibly one dead <stack>_default network per PR, forever. Passing a profile with no matching service is a no-op.
down -v never removes images Compose’s job ends at containers, volumes and networks. Per-PR images accumulate until the disk fills — and disk pressure evicts the warm build cache. Model images as an axis.