File size: 829 Bytes
61571e8
d34e1e5
 
61571e8
d34e1e5
 
 
 
 
 
 
 
 
 
 
 
 
 
61571e8
 
d34e1e5
 
 
61571e8
d34e1e5
 
 
61571e8
d34e1e5
 
61571e8
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
#!/bin/bash
PYTHON="${HOME}/miniforge3/bin/python3"
PORT_FILE="/tmp/numzoo.port"
cd "$(dirname "$0")/.."

# Kill the previously running instance using the saved port
if [ -f "$PORT_FILE" ]; then
  OLD_PORT=$(cat "$PORT_FILE")
  OLD_PID=$(lsof -ti :$OLD_PORT 2>/dev/null)
  if [ -n "$OLD_PID" ]; then
    echo "Killing previous instance on port $OLD_PORT (pid $OLD_PID)..."
    kill -9 $OLD_PID 2>/dev/null
    sleep 1
  fi
  rm -f "$PORT_FILE"
fi

$PYTHON app.py > /tmp/numzoo.log 2>&1 &
echo "Starting app..."
sleep 10

PORT=$(lsof -i :7860 -i :7861 -i :7862 -i :7863 -i :7864 -i :7865 2>/dev/null \
       | grep LISTEN | tail -1 | grep -oE '786[0-9]')
if [ -z "$PORT" ]; then
  echo "❌ App failed to start. Logs:"
  cat /tmp/numzoo.log
  exit 1
fi

echo $PORT > "$PORT_FILE"
echo "✅ App running on http://localhost:$PORT"