Files
mozimo.in/entrypoint.sh
T

52 lines
1.8 KiB
Bash

#!/usr/bin/env bash
# Mozimo container entrypoint — runs PocketBase (editorial CMS) and the
# TanStack Start SSR server side by side. If either process dies the
# container exits, so the restart policy brings the pair back together.
set -euo pipefail
PB_PORT="${PB_PORT:-8090}"
PB_DATA_DIR="${PB_DATA_DIR:-/app/pb_data}"
# On a fresh volume no superuser exists — ensure one from env (idempotent;
# on restarts it re-aligns the password with the env values).
if [ -n "${PB_SUPERUSER_EMAIL:-}" ] && [ -n "${PB_SUPERUSER_PASSWORD:-}" ]; then
echo "[entrypoint] ensuring pocketbase superuser ${PB_SUPERUSER_EMAIL}"
/usr/local/bin/pocketbase superuser upsert \
"${PB_SUPERUSER_EMAIL}" "${PB_SUPERUSER_PASSWORD}" --dir="${PB_DATA_DIR}"
fi
echo "[entrypoint] starting pocketbase on :${PB_PORT}"
/usr/local/bin/pocketbase serve \
--http="0.0.0.0:${PB_PORT}" \
--dir="${PB_DATA_DIR}" &
PB_PID=$!
# give PocketBase a moment, then seed schema + defaults (idempotent, no-op
# when records already exist or no superuser env is provided)
(
sleep 2
if [ ! -f pb-seed.mjs ]; then
echo "[entrypoint] WARNING: pb-seed.mjs missing from image — the image was built from a stale checkout; rebuild it"
elif node pb-seed.mjs; then
echo "[entrypoint] pocketbase seed complete"
else
echo "[entrypoint] pocketbase seed skipped/failed — site falls back to bundled defaults"
fi
) &
echo "[entrypoint] starting web server on :${PORT:-3000}"
node server.mjs &
APP_PID=$!
shutdown() {
echo "[entrypoint] SIGTERM received — shutting down"
kill -TERM "$PB_PID" "$APP_PID" 2>/dev/null || true
wait "$PB_PID" "$APP_PID" 2>/dev/null || true
exit 0
}
trap shutdown TERM INT
wait -n "$PB_PID" "$APP_PID"
echo "[entrypoint] a child process exited — stopping container"
shutdown