#!/usr/bin/env bash # ============================================================================= # entrypoint.sh — TRM directus image boot flow # # Apply order (non-negotiable, per ROADMAP design rule #3): # 1. db-init runner — applies db-init/*.sql migrations against Postgres, # guarded by the migrations_applied table. Owns DDL Directus does not # manage (positions hypertable, faulty column). # 2. Directus schema apply — applies snapshots/schema.yaml so the running # schema matches what's in git. No-op if schema.yaml doesn't exist # (Phase 1 task 1.4/1.5 hasn't produced one yet). # 3. Directus bootstrap — idempotent first-boot setup (admin user, system # tables). Already-bootstrapped instances treat this as a fast no-op. # 4. Directus start under pm2-runtime — the upstream image's actual run # pattern. pm2 provides crash recovery and signal handling inside the # container. # # Any failure halts boot (set -euo pipefail). Operators see a clear log line # in container output telling them which step failed. # ============================================================================= set -euo pipefail log() { printf '[entrypoint] %s\n' "$*" } log "step 1/4: db-init" /directus/scripts/apply-db-init.sh log "step 2/4: directus schema apply" /directus/scripts/schema-apply.sh log "step 3/4: directus bootstrap" node /directus/cli.js bootstrap log "step 4/4: directus start (pm2-runtime)" exec pm2-runtime start /directus/ecosystem.config.cjs