File size: 1,774 Bytes
c7e434a
 
 
 
 
 
2195b13
 
5395cd1
2195b13
c7e434a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/bin/bash

echo "=========================================="
echo "Starting Swara API Services"
echo "=========================================="

# Fix cache permissions on startup (in case of permission issues)
chmod -R 777 /.cache 2>/dev/null || true
chmod -R 777 /data/.cache 2>/dev/null || true

# Fix OpenMP warning - set proper thread count
export OMP_NUM_THREADS=4

# Set environment variables for Redis (localhost since in same container)
export REDIS_HOST=localhost
export REDIS_PORT=6379
export REDIS_DB=0

# Start Redis in background with persistence DISABLED (in-memory only)
echo "[1/4] Starting Redis server (in-memory mode)..."
redis-server --daemonize yes --bind 127.0.0.1 --port 6379 \
    --save "" \
    --appendonly no \
    --maxmemory 512mb \
    --maxmemory-policy allkeys-lru

# Wait for Redis to be ready with timeout
echo "[2/4] Waiting for Redis to be ready..."
REDIS_TIMEOUT=30
ELAPSED=0
until redis-cli -h localhost -p 6379 ping 2>/dev/null | grep -q PONG; do
  if [ $ELAPSED -ge $REDIS_TIMEOUT ]; then
    echo "ERROR: Redis failed to start within ${REDIS_TIMEOUT}s"
    exit 1
  fi
  echo "   Waiting for Redis... (${ELAPSED}s)"
  sleep 2
  ELAPSED=$((ELAPSED + 2))
done

echo "   ✓ Redis is ready!"

# Start RQ worker in background
echo "[3/4] Starting RQ Worker..."
python -m app.worker &
WORKER_PID=$!
echo "   ✓ Worker started (PID: $WORKER_PID)"

# Give worker time to initialize
sleep 2

# Start FastAPI application
echo "[4/4] Starting FastAPI application..."
echo "=========================================="
echo "API will be available at:"
echo "  http://localhost:7860"
echo "  http://localhost:7860/docs (API Documentation)"
echo "=========================================="

uvicorn app.main:app --host 0.0.0.0 --port 7860