#!/bin/sh # Print startup information echo "===== Stremio for Hugging Face Spaces =====" echo "Starting at: $(date)" # Create data directory in /tmp (which should be writable) mkdir -p /tmp/.stremio-server echo "Created data directory in /tmp/.stremio-server" # Print environment info for debugging echo "Node version: $(node -v)" echo "NPM version: $(npm -v)" echo "User: $(whoami)" echo "Current working directory: $(pwd)" # Set environment variables export HOME=/tmp export STREMIO_USER_DATA_DIR=/tmp/.stremio-server export NO_CORS=1 export CASTING_DISABLED=1 export APP_PATH=/tmp/.stremio-server # Start proxy first to ensure Hugging Face health checks work echo "Starting proxy server on port 7860..." node /app/proxy.js & PROXY_PID=$! echo "Proxy started with PID: $PROXY_PID" # Find stremio-web-service-run.sh echo "Searching for Stremio server script..." STREMIO_SCRIPT=$(find / -name stremio-web-service-run.sh 2>/dev/null | head -1) # Try different methods to start Stremio server if [ -z "$STREMIO_SCRIPT" ]; then echo "WARNING: Could not find stremio-web-service-run.sh" echo "Trying minimal Node.js starter instead..." node /app/stremio-minimal.js & STREMIO_PID=$! else echo "Found Stremio script at: $STREMIO_SCRIPT" # Try to run the script directly with sh echo "Starting Stremio server on port 11470..." sh "$STREMIO_SCRIPT" & STREMIO_PID=$! fi # Check if Stremio started correctly sleep 5 if kill -0 $STREMIO_PID 2>/dev/null; then echo "Stremio server process is running with PID: $STREMIO_PID" # Try to verify if the server is actually responding echo "Checking if server is responding on port 11470..." TRIES=0 SERVER_UP=0 while [ $TRIES -lt 5 ]; do if nc -z localhost 11470 2>/dev/null; then echo "Server is responding on port 11470!" SERVER_UP=1 break fi echo "Waiting for server to start responding (attempt $((TRIES+1))/5)..." TRIES=$((TRIES+1)) sleep 3 done if [ $SERVER_UP -eq 1 ]; then # Keep container running echo "Stremio server is up and running" echo "Services started, monitoring processes..." wait else echo "WARNING: Stremio process is running but not responding on port 11470" echo "Trying minimal Node.js starter as fallback..." kill $STREMIO_PID node /app/stremio-minimal.js & STREMIO_PID=$! # Check again sleep 5 if kill -0 $STREMIO_PID 2>/dev/null && nc -z localhost 11470 2>/dev/null; then echo "Minimal starter is working! Monitoring processes..." wait else echo "ERROR: All Stremio server start attempts failed" kill $STREMIO_PID 2>/dev/null kill $PROXY_PID 2>/dev/null echo "FALLBACK: Using proxy-only mode" exec node /app/proxy-only.js fi fi else echo "ERROR: Stremio server failed to start" echo "Trying minimal Node.js starter as fallback..." node /app/stremio-minimal.js & STREMIO_PID=$! # Check again sleep 5 if kill -0 $STREMIO_PID 2>/dev/null; then echo "Minimal starter is working! Monitoring processes..." wait else echo "ERROR: All Stremio server start attempts failed" echo "Terminating proxy..." kill $PROXY_PID echo "FALLBACK: Using proxy-only mode" exec node /app/proxy-only.js fi fi