Spaces:
Sleeping
Sleeping
| # Pre-startup cleanup: ensure database files are in a clean state | |
| # This runs BEFORE the Node.js server starts. | |
| set -e | |
| DB_DIR="/data" | |
| DB_FILE="${DB_DIR}/realblocks.db" | |
| echo "[startup] Checking database state at ${DB_FILE}..." | |
| # Ensure data dir exists | |
| mkdir -p "${DB_DIR}" | |
| # If the DB file exists but isn't a valid SQLite file, remove it. | |
| if [ -f "${DB_FILE}" ]; then | |
| # Check SQLite magic header: "SQLite format 3\x00" | |
| HEADER=$(head -c 16 "${DB_FILE}" 2>/dev/null | head -c 15) | |
| if [ "${HEADER}" != "SQLite format 3" ]; then | |
| echo "[startup] Database file is corrupted (header: '${HEADER}'). Removing." | |
| rm -f "${DB_FILE}" "${DB_FILE}-wal" "${DB_FILE}-shm" "${DB_FILE}-journal" | |
| else | |
| echo "[startup] Database file looks valid." | |
| fi | |
| else | |
| echo "[startup] No existing database file. Will create fresh." | |
| fi | |
| # Also remove any orphaned WAL/SHM/journal files left over | |
| rm -f "${DB_FILE}-wal" "${DB_FILE}-shm" "${DB_FILE}-journal" 2>/dev/null || true | |
| echo "[startup] Starting server..." | |
| exec node server/dist/index.js | |