Spaces:
Runtime error
Runtime error
| # Create necessary directories in the persistent /data volume | |
| echo "Creating necessary directories in the persistent /data volume..." | |
| mkdir -p /data/postgresql/data /data/postgresql/run | |
| chmod 0700 /data/postgresql/data | |
| chmod 0755 /data/postgresql/run | |
| # Initialize PostgreSQL if not already initialized | |
| echo "Initializing PostgreSQL if not already initialized..." | |
| if [ ! -f "/data/postgresql/data/PG_VERSION" ]; then | |
| # Initialize database | |
| echo "Initializing database..." | |
| initdb -D /data/postgresql/data | |
| # Modify pg_hba.conf to allow local connections | |
| echo "local all all trust" > /data/postgresql/data/pg_hba.conf | |
| echo "host all all 127.0.0.1/32 trust" >> /data/postgresql/data/pg_hba.conf | |
| echo "host all all 0.0.0.0/0 trust" >> /data/postgresql/data/pg_hba.conf | |
| fi | |
| # Start PostgreSQL with the persistent directories | |
| echo "Starting PostgreSQL..." | |
| # First, check if there's a postmaster.pid file and remove it if the process isn't running | |
| if [ -f "/data/postgresql/data/postmaster.pid" ]; then | |
| pid=$(cat /data/postgresql/data/postmaster.pid | head -1) | |
| if ! kill -0 "$pid" 2>/dev/null; then | |
| echo "Removing stale PID file..." | |
| rm /data/postgresql/data/postmaster.pid | |
| fi | |
| fi | |
| pg_ctl -D /data/postgresql/data -o "-c listen_addresses='*' -c unix_socket_directories='/data/postgresql/run'" start | |
| # Create the 'node' database if it doesn't exist | |
| echo "Creating 'node' database if it doesn't exist..." | |
| createdb -h localhost node || true | |
| # Wait for PostgreSQL to be ready | |
| echo "Waiting for PostgreSQL to be ready..." | |
| until pg_isready -h localhost; do | |
| echo "Waiting for PostgreSQL to be ready..." | |
| sleep 1 | |
| done | |
| # Set NEXTAUTH_URL based on SPACE_HOST if available | |
| if [ -n "$SPACE_ID" ]; then | |
| echo "Setting NEXTAUTH_URL to https://huggingface.co/spaces/${SPACE_ID}" | |
| export NEXTAUTH_URL="https://huggingface.co/spaces/${SPACE_ID}" | |
| else | |
| echo "WARNING: SPACE_ID not found" | |
| fi | |
| # Update DATABASE_URL to use TCP connection | |
| export DATABASE_URL="postgresql://postgres:postgres@localhost:5432/node" | |
| # Export these environment variables to influence Next.js binding | |
| export HOSTNAME="0.0.0.0" | |
| export HOST="0.0.0.0" | |
| export PORT=3000 | |
| # Start Next.js in the background | |
| ./web/entrypoint.sh node ./web/server.js \ | |
| --keepAliveTimeout 110000 \ | |
| --hostname "0.0.0.0" \ | |
| --port 3000 \ | |
| --experimental-hostname-validation=false \ | |
| --experimental-https=false & | |
| # Wait a moment for the server to start | |
| sleep 5 | |
| # Debug network information | |
| echo "Network Debug Information:" | |
| echo "-------------------------" | |
| ip addr show | |
| echo "-------------------------" | |
| netstat -tulpn | |
| echo "-------------------------" | |
| # Keep the script running | |
| wait |