Before you start
Check the schema.migrate status reports the applied version and exits
non-zero if a previous migration stopped part-way, which is the one state you
must not deploy on top of:
migrate status.
Back up PostgreSQL. It holds every scan, finding, triage decision, accepted
risk, policy verdict and schedule in the deployment, and a migration applied to
it is applied for real.
down, so the schema is reversible in principle. But a
down returns the schema, not the data a column drop took with it. The backup
is what makes a rollback recover the second thing as well as the first.
You do not need to back up Redis or the scanner cache:
Discarding
scanner_cache costs one slow scan while roughly 50 MB is
re-fetched. That is a reasonable thing to do deliberately if you suspect a
corrupt cache; it is not something to do routinely, because a worker that starts
with a cold cache also starts with no vulnerability database, and the first scan
pays for both.
The upgrade
running migrations: … and does
not serve traffic. That is the intended behaviour: a binary that finds a schema
it does not understand should refuse to start rather than produce confusing
runtime errors later.
Production: migrations are a separate step
infra/docker/docker-compose.prod.yml and the Kubernetes base set
RUN_MIGRATIONS_ON_START=false, because there the API and worker connect as
restricted login roles that cannot change the schema. A one-shot migrate up
runs as the schema owner first (MIGRATION_DATABASE_URL), and the API and
worker start only after it succeeds; each then checks that the schema is the
one it was built for and refuses to start if not. infra/scripts/deploy.sh
runs that sequence with a backup in front of it. See
migrate.
Order of restart
Restart workers before or after the API: either is safe, and neither needs coordination.- A worker killed mid-scan has its lease expire, and the reaper returns the scan
to
queued. An abrupt stop costs one lease interval, not one lost scan. - A worker that shuts down on a signal leaves the interrupted run claimed
and lets its lease expire, so the reaper returns it to
queuedintact, the same treatment a killed worker gets. It is deliberately not recorded as a failure: doing so would spend one of the scan’s attempts on work that was never actually tried, and three rolling restarts hitting the same scan would exhaust its retry budget and fail it permanently. - An API restart loses nothing: the scan row is committed before the response is returned, and the dispatcher republishes anything whose wakeup was lost.
- On
SIGTERMthe API stops accepting connections and waits at most 20 seconds for open ones (a slow download, an idle keep-alive client), then closes its database pools and exits. Give it a stop grace period longer than that: the production Compose file sets 30 seconds onapi, and the Kubernetes default is 30. Before 2026-10-13 the wait had no limit, so a single keep-alive client held the process until the orchestrator killed it.
SCAN_WORKER_ENABLED=true on the API),
the same applies: the restart is just one process instead of two.
What downtime costs a schedule
Nothing is silently lost, and nothing is replayed thirty times. If TRUSTIVAN is down for thirty days, thirty daily occurrences come due at once. The policy is run once, realign, count the rest:- One scan runs, not thirty. Thirty identical scans of one image would cost thirty times the registry bandwidth and tell you nothing the last one alone would not.
next_run_atadvances in whole intervals from the planned time, so the original phase is preserved. A schedule that ran at 02:00 keeps running at 02:00 rather than drifting to whenever the system came back.- The skipped occurrences accumulate on the schedule as
missed_runsand are shown in the dashboard, because a gap in coverage that nobody is told about is indistinguishable from continuous coverage.
Verifying an upgrade
- A scan completes. Submit one against a small public image and poll it to a terminal state.
database_stateon that scan isfresh. If the scanner cache was discarded or egress is blocked, this is where it shows.trustowl_scheduler_lag_secondsis falling back toward normal. A dead scheduler produces no work, so every other figure looks healthy. See Health and metrics.
Rolling back
Roll back the code, not the schema: put the previous images back and leave the database where the newer version left it. The application accepts a schema ahead of its own migrations, which is what makes that work whenever the migration was additive, and additive is the default for that reason. When it does not work, the migration was not backward-compatible, and the recovery is restoring the backup, not rolling the schema back:migrate down N reverses the last N migrations and the data in whatever they
drop, so it is a development tool rather than an upgrade rollback tool. It
refuses to drop the audit trail without --force-drop-audit.
This is the practical reason the backup is not optional. Between a schema
down that drops a column and a pg_dump taken twenty minutes earlier, only
one of them returns the triage decisions that were in that column.
Deploy and roll back with the scripts
On a single Compose host,infra/scripts/deploy.sh runs the upgrade as gated
steps, and each one either succeeds or stops the deploy:
- Preflight: changes nothing, and refuses anything that would fail later.
- Backup: before the migration, because that is the state to return to.
It refuses to run without
BACKUP_PUBLIC_KEYunless the environment file saysBACKUP_ALLOW_UNENCRYPTED=true; see Backup and recovery.--skip-backupskips it when you have just taken one. - Migrate: the one-shot job, as the schema owner.
- Start: the API, the worker and the frontends.
- Health:
/readyfrom inside the container, so it tests the application and not the proxy. - Smoke: the deployed system end to end.
--no-smokestops at health, for a stack with no public URL yet.
ENV_FILE and COMPOSE_PROJECT_NAME in the shell. Two
more settings, read from the shell first and then from the environment file,
fit the scripts to a host that does not run every service:
A successful deploy ends by printing the exact
rollback.sh command for the
images it replaced. The running image is given its own rollback-<timestamp>
tag first, because a rebuild on the host moves the ordinary tag to the new
build. If that image is already gone from the local store, the script says
there is nothing to roll back to rather than print a target that is not one.
rollback.sh recreates only the services whose image changes (api and
worker for the backend), with --no-deps, so migrate, db-roles,
Postgres and Redis are not touched and the previous image’s migrations never
run against the newer schema. It respects DEPLOY_SERVICES and runs the
post-up hook.
Changed on 2026-10-13. Earlier versions of both scripts ran a bare
docker compose up -d. In a rollback that started the previous image’s
migrate against the newer schema, which exits with “no migration found for
version N”, and Compose then left api and worker in Created: rolling back
a deploy that carried a migration took the product down. The earlier backup
step also wrote a plaintext dump when BACKUP_PUBLIC_KEY was unset. See the
upgrade notes.Configuration changes during an upgrade
Two settings are worth re-checking whenever you change versions, because both fail closed and both fail at startup rather than at use:ENVmust remain something other thandevelopmentin a deployment. If a deploy accidentally sets it todevelopment, secrets are regenerated per process instead of being required, and every session is invalidated on each restart.VULN_DB_PROVIDER=mirrorrequiresVULN_DB_REPOSITORIES. Startup fails if it is empty rather than silently reaching for the public internet, which either fails confusingly or, worse, succeeds and defeats the isolation you configured.
What deployment tooling exists
Worth restating here, because an upgrade is when people go looking for it. Compose on a single host is the recommended path, and the gated sequence isinfra/scripts/deploy.sh (preflight, backup, migrate, start, health, smoke)
with infra/scripts/rollback.sh beside it; see
above. Kubernetes manifests exist as a
Kustomize base and its overlays, driven by make deploy-demo, make deploy-prod and scripts/deploy-k8s.sh hetzner; there is no Helm chart for
the product. Terraform provisions a Hetzner cluster
optionally and never deploys the application.
There is no make deploy-staging and no make deploy-production: those names
do not exist. See Topology for the full account of
what is and is not included.