fix: improve entrypoint.sh volume mount handling

- Add 3 second delay to wait for Easypanel volume mount
- Check file size as backup (seeded DB > 1KB, empty < 1KB)
- Check content table count as primary validation
- Safer fallback if any check fails

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Kunthawat Greethong
2026-05-02 09:48:40 +07:00
parent 3207dc8c46
commit 30eeee186f

View File

@@ -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..."
# 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
else
echo "Database exists with content, starting normally..."
fi
exec node ./dist/server/entry.mjs