diff --git a/entrypoint.sh b/entrypoint.sh index aa64583..b7e3369 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,11 +1,21 @@ #!/bin/sh -# Only seed on first launch (when data.db doesn't exist or is empty) -# Check if content table has any entries -if [ ! -f data.db ] || ! sqlite3 data.db "SELECT COUNT(*) FROM content" 2>/dev/null | grep -q "^[1-9]"; then - echo "Database missing or empty, running emdash init & seed..." - pnpm exec emdash init - pnpm exec emdash seed -else - echo "Database exists with content, starting normally..." +# Wait for volume mount to settle (Easypanel may mount after container starts) +sleep 3 + +# Check if data.db exists and has content +# Using file size as backup check (empty DB is ~8KB, seeded DB is much larger) +DB_SIZE=$(stat -c%s /app/data.db 2>/dev/null || stat -f%z /app/data.db 2>/dev/null || echo "0") + +if [ -f /app/data.db ] && [ "$DB_SIZE" -gt 1000 ]; then + # DB exists and has size > 1KB, check if it has content + if sqlite3 /app/data.db "SELECT COUNT(*) FROM content" 2>/dev/null | grep -q "^[1-9]"; then + echo "Database exists with content, starting normally..." + exec node ./dist/server/entry.mjs + fi fi + +echo "Database missing, empty, or corrupted. Running emdash init & seed..." +cd /app +pnpm exec emdash init +pnpm exec emdash seed exec node ./dist/server/entry.mjs \ No newline at end of file