Jeremy Jones commited on
Commit
4a2041c
·
1 Parent(s): bd7e398

Seed board on first boot from Mac Mini snapshot

Browse files
Files changed (2) hide show
  1. entrypoint.sh +21 -2
  2. sql/002_seed.sql +0 -0
entrypoint.sh CHANGED
@@ -62,9 +62,14 @@ if [ ! -f "${PGDATA}/postgresql.conf" ]; then
62
  echo "listen_addresses = 'localhost'" >> "${PGDATA}/postgresql.conf"
63
  fi
64
 
65
- # Start Postgres in the background.
 
66
  echo "[kanbot] starting Postgres ..."
67
- pg_ctl -D "${PGDATA}" -l "${PGDATA}/server.log" start -w
 
 
 
 
68
 
69
  # Wait for it to accept connections.
70
  wait_for_host 127.0.0.1 "$PORT"
@@ -83,5 +88,19 @@ echo "[kanbot] applying schema ..."
83
  SCHEMA_FILE="${KANBOT_SCHEMA_SQL:-/app/sql/001_schema_quoted.sql}"
84
  psql "${DATABASE_URL}" -f "${SCHEMA_FILE}"
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  echo "[kanbot] local Postgres ready; starting web server on :${WEB_PORT}"
87
  exec python -m web.server
 
62
  echo "listen_addresses = 'localhost'" >> "${PGDATA}/postgresql.conf"
63
  fi
64
 
65
+ # Start Postgres in the background (skip if a server is already running —
66
+ # the container may have been restarted while Postgres stayed up).
67
  echo "[kanbot] starting Postgres ..."
68
+ if pg_ctl -D "${PGDATA}" status 2>/dev/null | grep -q "pg_ctl: server"; then
69
+ echo "[kanbot] Postgres already running"
70
+ else
71
+ pg_ctl -D "${PGDATA}" -l "${PGDATA}/server.log" start -w
72
+ fi
73
 
74
  # Wait for it to accept connections.
75
  wait_for_host 127.0.0.1 "$PORT"
 
88
  SCHEMA_FILE="${KANBOT_SCHEMA_SQL:-/app/sql/001_schema_quoted.sql}"
89
  psql "${DATABASE_URL}" -f "${SCHEMA_FILE}"
90
 
91
+ # Seed the board from the Mac Mini snapshot on first boot (when the table is
92
+ # empty). The seed file ships in the repo; it is idempotent (ON CONFLICT DO
93
+ # NOTHING) so re-runs are safe and a manually-seeded board is never clobbered.
94
+ SEED_FILE="${KANBOT_SEED_SQL:-/app/sql/002_seed.sql}"
95
+ if [ -f "${SEED_FILE}" ]; then
96
+ N=$(psql "${DATABASE_URL}" -tAc "SELECT count(*) FROM cards" 2>/dev/null || echo 0)
97
+ if [ "${N}" = "0" ]; then
98
+ echo "[kanbot] seeding board from ${SEED_FILE} ..."
99
+ psql "${DATABASE_URL}" -f "${SEED_FILE}"
100
+ else
101
+ echo "[kanbot] board already has ${N} cards; skipping seed"
102
+ fi
103
+ fi
104
+
105
  echo "[kanbot] local Postgres ready; starting web server on :${WEB_PORT}"
106
  exec python -m web.server
sql/002_seed.sql ADDED
The diff for this file is too large to render. See raw diff