Files
hops/docker-entrypoint.sh
2026-09-02 17:45:38 +00:00

46 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
set -e
# Data directory for PocketBase
DATA_DIR=${PB_DATA_DIR:-/app/pb_data}
mkdir -p "$DATA_DIR"
echo "[hops] Starting PocketBase backend on port 8090..."
/app/pocketbase serve --http 0.0.0.0:8090 --dir "$DATA_DIR" &
PB_PID=$!
# Wait for PocketBase to become healthy
echo "[hops] Waiting for PocketBase to initialize..."
until curl -s http://127.0.0.1:8090/api/health > /dev/null 2>&1; do
sleep 0.3
done
echo "[hops] PocketBase is live and healthy."
# Upsert admin superuser if configured
ADMIN_EMAIL=${PB_ADMIN_EMAIL:-admin@hopsngrains.com}
ADMIN_PASSWORD=${PB_ADMIN_PASSWORD:-HopsPassword1234!}
if [ -n "$ADMIN_EMAIL" ] && [ -n "$ADMIN_PASSWORD" ]; then
/app/pocketbase superuser upsert "$ADMIN_EMAIL" "$ADMIN_PASSWORD" --dir "$DATA_DIR" > /dev/null 2>&1 || true
fi
# Graceful shutdown handler
cleanup() {
echo "[hops] Shutting down services..."
kill -TERM "$NODE_PID" 2>/dev/null || true
kill -TERM "$PB_PID" 2>/dev/null || true
wait "$NODE_PID" 2>/dev/null || true
wait "$PB_PID" 2>/dev/null || true
exit 0
}
trap cleanup SIGTERM SIGINT
echo "[hops] Starting TanStack Start frontend server on port ${PORT:-3000}..."
node /app/frontend/.output/server/index.mjs &
NODE_PID=$!
# Wait for either process to terminate
wait -n "$PB_PID" "$NODE_PID"
cleanup