|
| 1 | +# Init tasks |
| 2 | + |
| 3 | +Init tasks are one-time operations the API server performs at startup, before |
| 4 | +the main server begins serving traffic. They prepare the database schema, seed |
| 5 | +default objects, and bring the durable execution engine to a consistent state. |
| 6 | + |
| 7 | +## Lifecycle |
| 8 | + |
| 9 | +Init tasks run before the HTTP listener starts and before background workers |
| 10 | +initialize. They block startup. If any task fails, the JVM exits and the |
| 11 | +container does not begin serving traffic. |
| 12 | + |
| 13 | +The management server starts before init tasks run and exposes the |
| 14 | +[startup health endpoint](../../guides/administration/configuring-observability.md#configuring-kubernetes-health-probes) |
| 15 | +at `/health/started`, which reports per-task status (`STARTED`, `COMPLETED`, |
| 16 | +`FAILED`) during execution. |
| 17 | + |
| 18 | +By default, init tasks run in every API server container. To coordinate across |
| 19 | +instances, the executor acquires a session-level PostgreSQL [advisory lock], |
| 20 | +so only one container performs each task at a time. Remaining containers wait |
| 21 | +for the lock, then confirm there is nothing left to do. |
| 22 | + |
| 23 | +!!! warning |
| 24 | + Session-level advisory locks are incompatible with PgBouncer in |
| 25 | + `transaction` pooling mode. When using a transaction-mode connection |
| 26 | + pooler, configure a separate [init data source](#data-source) that |
| 27 | + connects directly to PostgreSQL. |
| 28 | + |
| 29 | +## Tasks |
| 30 | + |
| 31 | +| Task | Purpose | Enable property | |
| 32 | +|------|---------|-----------------| |
| 33 | +| Database migration | Runs [Flyway](database.md#schema-migrations) migrations against the Dependency-Track schema. Creates required [extensions](database.md#extensions). | [`dt.init-task.database-migration.enabled`](properties.md#dtinit-taskdatabase-migrationenabled) | |
| 34 | +| Database partition maintenance | Creates [table partitions] required for [time series metrics](../../concepts/time-series-metrics.md). | [`dt.init-task.database-partition-maintenance.enabled`](properties.md#dtinit-taskdatabase-partition-maintenanceenabled) | |
| 35 | +| Database seeding | Populates default permissions, teams, users, licenses, license groups, repositories, and configuration properties. Idempotent. Skips on later startups when the build identifier has not changed. | [`dt.init-task.database-seeding.enabled`](properties.md#dtinit-taskdatabase-seedingenabled) | |
| 36 | +| Dex engine database migration | Runs schema migrations for the [durable execution engine](dex-engine.md). | [`dt.init-task.dex-engine-database-migration.enabled`](properties.md#dtinit-taskdex-engine-database-migrationenabled) | |
| 37 | + |
| 38 | +Per-task enable properties take effect only when |
| 39 | +[`dt.init-tasks.enabled`](properties.md#dtinit-tasksenabled) is `true`. |
| 40 | + |
| 41 | +## Data source |
| 42 | + |
| 43 | +By default, init tasks use the `default` [data source](datasources.md). |
| 44 | +Override this with |
| 45 | +[`dt.init-tasks.datasource.name`](properties.md#dtinit-tasksdatasourcename) |
| 46 | +to route them through a separate connection pool. |
| 47 | + |
| 48 | +The most common reason: centralized connection pooling with PgBouncer in |
| 49 | +`transaction` mode, which requires init tasks to bypass the pooler and |
| 50 | +connect to PostgreSQL directly. The default data source connects through |
| 51 | +PgBouncer, while the init data source connects to PostgreSQL directly so |
| 52 | +session-level advisory locks remain usable. See |
| 53 | +[centralized connection pooling](../../guides/administration/configuring-database.md#centralised-connection-pooling) |
| 54 | +for an example. |
| 55 | + |
| 56 | +When the init data source exists solely to serve init tasks, set |
| 57 | +[`dt.init-tasks.datasource.close-after-completion`](properties.md#dtinit-tasksdatasourceclose-after-completion) |
| 58 | +to `true`. The API server closes the connection pool once tasks finish, |
| 59 | +freeing its connections. |
| 60 | + |
| 61 | +## Init-only containers |
| 62 | + |
| 63 | +Setting |
| 64 | +[`dt.init-tasks.exit-after-completion`](properties.md#dtinit-tasksexit-after-completion) |
| 65 | +to `true` causes the JVM to exit with status `0` once init tasks succeed, |
| 66 | +without starting the main server. This supports a dedicated init container |
| 67 | +pattern, where a short-lived container runs init tasks and exits before |
| 68 | +long-lived API server containers start. |
| 69 | + |
| 70 | +In this pattern, the long-lived containers set |
| 71 | +[`dt.init-tasks.enabled`](properties.md#dtinit-tasksenabled) to `false` to |
| 72 | +skip init tasks on startup. |
| 73 | + |
| 74 | +## Configuration |
| 75 | + |
| 76 | +* [`dt.init-tasks.enabled`](properties.md#dtinit-tasksenabled) |
| 77 | +* [`dt.init-tasks.datasource.name`](properties.md#dtinit-tasksdatasourcename) |
| 78 | +* [`dt.init-tasks.datasource.close-after-completion`](properties.md#dtinit-tasksdatasourceclose-after-completion) |
| 79 | +* [`dt.init-tasks.exit-after-completion`](properties.md#dtinit-tasksexit-after-completion) |
| 80 | +* [`dt.init-task.database-migration.enabled`](properties.md#dtinit-taskdatabase-migrationenabled) |
| 81 | +* [`dt.init-task.database-partition-maintenance.enabled`](properties.md#dtinit-taskdatabase-partition-maintenanceenabled) |
| 82 | +* [`dt.init-task.database-seeding.enabled`](properties.md#dtinit-taskdatabase-seedingenabled) |
| 83 | +* [`dt.init-task.dex-engine-database-migration.enabled`](properties.md#dtinit-taskdex-engine-database-migrationenabled) |
| 84 | + |
| 85 | +[advisory lock]: https://www.postgresql.org/docs/current/explicit-locking.html#ADVISORY-LOCKS |
| 86 | +[table partitions]: https://www.postgresql.org/docs/current/ddl-partitioning.html |
0 commit comments