| | #!/bin/sh |
| |
|
| | |
| | echo "===== Stremio for Hugging Face Spaces =====" |
| | echo "Starting at: $(date)" |
| |
|
| | |
| | mkdir -p /tmp/.stremio-server |
| | echo "Created data directory in /tmp/.stremio-server" |
| |
|
| | |
| | echo "Node version: $(node -v)" |
| | echo "NPM version: $(npm -v)" |
| | echo "User: $(whoami)" |
| | echo "Current working directory: $(pwd)" |
| |
|
| | |
| | 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 |
| |
|
| | |
| | echo "Starting proxy server on port 7860..." |
| | node /app/proxy.js & |
| | PROXY_PID=$! |
| | echo "Proxy started with PID: $PROXY_PID" |
| |
|
| | |
| | echo "Searching for Stremio server script..." |
| | STREMIO_SCRIPT=$(find / -name stremio-web-service-run.sh 2>/dev/null | head -1) |
| |
|
| | |
| | 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" |
| |
|
| | |
| | echo "Starting Stremio server on port 11470..." |
| | sh "$STREMIO_SCRIPT" & |
| | STREMIO_PID=$! |
| | fi |
| |
|
| | |
| | sleep 5 |
| | if kill -0 $STREMIO_PID 2>/dev/null; then |
| | echo "Stremio server process is running with PID: $STREMIO_PID" |
| | |
| | |
| | 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 |
| | |
| | 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=$! |
| | |
| | |
| | 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=$! |
| | |
| | |
| | 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 |