---
title: "Incident runbook"
description: "Detect, triage and roll back a self-hosted TRUSTIVAN deployment with the commands the deploy scripts print, and the record of a rehearsal run end to end."
---

This page is for whoever is on call for a Docker Compose deployment of
TRUSTIVAN. It assumes the operator scripts in `infra/scripts/` and the
monitoring profile ([Observability](/deployment/observability)). Every command
runs from the repository checkout on the host, against one stack:

```bash
export ENV_FILE=/path/to/stack.env          # the stack's env file
export COMPOSE_PROJECT_NAME=<stack>         # e.g. trustivan-app
C="docker compose -f infra/docker/docker-compose.prod.yml --env-file $ENV_FILE -p $COMPOSE_PROJECT_NAME"
```

## 1. Detect

An incident starts with one of three signals:

| Signal | Where | Means |
|---|---|---|
| An alert fires | Alertmanager's receiver (`ALERTMANAGER_CONFIG`) | Every alert's `runbook` annotation names the section of [Observability](/deployment/observability) to read |
| `deploy.sh` stops | Its last lines | A gate failed: preflight, backup, migration, health or smoke. It prints the rollback command when one applies |
| `/ready` is not 200 | `curl -s 127.0.0.1:8080/ready` (`API_BIND`) | The API cannot reach PostgreSQL; the body lists each dependency |

Confirm what is firing, rather than what one person saw:

```bash
$C exec -T prometheus wget -qO- http://127.0.0.1:9090/api/v1/alerts
infra/scripts/monitoring.sh status      # rules loaded, targets up, backup metric visible
```

## 2. Triage

Answer three questions in order, because the order decides the fix.

1. **Did a deploy just happen?** If the incident began within minutes of
   `deploy.sh`, assume the release until shown otherwise and go to step 3.
   `deploy.sh` printed the previous images; they are also in the shell history.
2. **What is not running?** `$C ps` shows each service's state. `Restarting`
   means it starts and exits: `$C logs --tail 50 <service>` names the reason.
3. **Is it a dependency?** `/ready` names the database and the cache.
   PostgreSQL down stops the API; Redis down only slows scans (the worker polls
   PostgreSQL instead) and does not need a rollback. A full disk on the worker
   fails scans with "the scanning worker ran out of disk space": free space,
   and they are retried.

## 3. Roll back a release

`rollback.sh` puts the previous images back and leaves the schema alone. Use
the exact command `deploy.sh` printed: at the end of a successful deploy
(`to roll back:  infra/scripts/rollback.sh --to-backend '…' --to-dashboard '…'`)
or at the gate that stopped it (`Roll back with:  infra/scripts/rollback.sh
--to-backend '…'`).

```bash
infra/scripts/rollback.sh --to-backend '<previous backend image>' [--to-dashboard '<previous dashboard image>']
#   prints the plan, asks to proceed (ASSUME_YES=1 for a non-interactive shell),
#   restarts, then checks /ready, the schema, tenant isolation and the roles
```

If the previous image fails against the current schema, the release carried a
migration that was not backward-compatible. Code rollback cannot fix that:
restore the backup `deploy.sh` took before migrating (`*-pre-deploy.dump.age`
in `BACKUP_DIR`) with `infra/scripts/restore.sh`, as
[Backup and recovery](/deployment/backup-and-recovery) describes.

## 4. Verify, then close

```bash
curl -s -o /dev/null -w '%{http_code}\n' 127.0.0.1:8080/ready    # 200
infra/scripts/monitoring.sh status                               # every target up
$C exec -T prometheus wget -qO- http://127.0.0.1:9090/api/v1/alerts   # the alert is gone
infra/scripts/smoke.sh                                           # needs the public URL
```

Write down the timeline (first signal, decision, rollback, recovery) while it
is fresh. The rehearsal below is the shape to follow.

## Rehearsal, 2026-11-11

Run on a local stack built from this repository: the production Compose file,
PostgreSQL, Redis, the API and the worker on a locally built backend image,
three organizations, and the monitoring profile on. The "bad release" was the
same image with an API that exits at start with a configuration error.

| Time (UTC) | Step | What happened |
|---|---|---|
| 17:22:41 | Deploy | `deploy.sh --no-smoke` with `BACKEND_IMAGE=…-bad`; preflight passed |
| 17:22:46 | Backup | `✓ backup complete: …/trustowl-20261111T172243Z-pre-deploy.dump.age` |
| 17:22:57 | Start | Services started; the API began restarting |
| 17:23:12 | Detect | `TrustOwlAPIDown` pending in Prometheus |
| ~17:25:12 | Detect | `TrustOwlAPIDown` firing, and present in Alertmanager |
| 17:26:04 | Gate | `✗ deploy failed at the health gate. The new images are running but not serving.` `Roll back with:  infra/scripts/rollback.sh --to-backend 'trustowl-backend:w22ops'` |
| 17:26:10 | Triage | `$C ps`: `api Restarting (1)`; `$C logs --tail 3 api`: `FATAL config: SCAN_POLICY_BUNDLE is required (simulated bad release)` |
| 17:26:16 | Roll back | The printed command, which refused without a terminal (`set ASSUME_YES=1 deliberately`), then ran with `ASSUME_YES=1` |
| 17:26:58 | Recover | `✓ the rolled-back API reports ready`, schema 163 not dirty, 70 tenant-isolation policies, `✓ rollback complete` |
| 17:27:50 | Verify | `/ready` 200; `monitoring.sh status`: all four targets up; `TrustOwlAPIDown` resolved |

Four minutes from the bad start to a serving API, most of it the health gate's
wait. What the rehearsal did not cover: a real paging receiver (the example
Alertmanager file was used, so the alert reached nobody), the smoke test (no
public URL), and a release whose migration forces a restore.
