File size: 3,298 Bytes
594bd92
 
bfe9c22
 
 
 
 
 
 
 
 
594bd92
 
bfe9c22
 
594bd92
e1d546a
 
 
 
 
76ff187
828ee24
bfe9c22
 
 
 
 
594bd92
76ff187
 
 
 
 
 
 
 
 
 
 
 
bfe9c22
76ff187
 
 
 
 
594bd92
76ff187
 
 
 
 
 
 
 
 
e1d546a
76ff187
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e1d546a
76ff187
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e1d546a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/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