researchos / start.sh
Universities's picture
Upload 4 files
a68985d verified
Raw
History Blame Contribute Delete
3.23 kB
#!/bin/bash
set -e
echo "=========================================="
echo " ResearchOS MVP - Hugging Face Spaces"
echo "=========================================="
# Initialize SQLite database
echo "[1/9] Initializing SQLite database..."
python3 << 'PYEOF'
import os
from sqlalchemy import create_engine
# Import all model bases
import sys
sys.path.insert(0, '/app')
# Create engine
engine = create_engine('sqlite:///app/researchos.db', echo=False)
# Create tables by importing main modules
from services.auth_service.src.main import Base as AuthBase
from services.project_service.src.main import Base as ProjectBase
from services.manuscript_service.src.main import Base as ManuscriptBase
from services.verification_service.src.main import Base as VerificationBase
AuthBase.metadata.create_all(engine)
ProjectBase.metadata.create_all(engine)
ManuscriptBase.metadata.create_all(engine)
VerificationBase.metadata.create_all(engine)
print("Database initialized successfully")
PYEOF
# Function to start a service
start_service() {
local name=$1
local port=$2
local cmd=$3
echo "[START] $name on port $port..."
eval "$cmd > /tmp/$name.log 2>&1 &"
echo $! > /tmp/$name.pid
}
# Start all backend services
start_service "auth-service" "8005" "python3 services/auth-service/src/main.py"
start_service "project-service" "8002" "python3 services/project-service/src/main.py"
start_service "manuscript-service" "8007" "python3 services/manuscript-service/src/main.py"
start_service "analysis-service" "8001" "python3 services/analysis-service/src/main.py"
start_service "agent-service" "8004" "python3 services/agent-service/src/main.py"
start_service "verification-service" "8006" "python3 services/verification-service/src/main.py"
# Wait for services to be ready
echo "[2/9] Waiting for services to boot..."
sleep 5
# Start API Gateway
start_service "api-gateway" "8000" "python3 services/api-gateway/src/main.py"
sleep 3
# Start Next.js frontend on port 7860 (HF Spaces requirement)
echo "[3/9] Starting Next.js frontend on port 7860..."
cd /app/apps/web && PORT=7860 node server.js > /tmp/web.log 2>&1 &
echo $! > /tmp/web.pid
echo ""
echo "=========================================="
echo " ResearchOS is starting up!"
echo "=========================================="
echo ""
echo "Services:"
echo " - Auth: http://localhost:8005"
echo " - Projects: http://localhost:8002"
echo " - Manuscripts: http://localhost:8007"
echo " - Analysis: http://localhost:8001"
echo " - Agents: http://localhost:8004"
echo " - Verification:http://localhost:8006"
echo " - API Gateway: http://localhost:8000"
echo " - Web App: http://localhost:7860"
echo ""
echo "Logs available in /tmp/*.log"
echo ""
# Health check loop
for i in {1..30}; do
if curl -s http://localhost:8000/health > /dev/null 2>&1; then
echo "[✓] API Gateway is ready!"
break
fi
echo "[...] Waiting for API Gateway ($i/30)..."
sleep 2
done
echo ""
echo "=========================================="
echo " ResearchOS is LIVE!"
echo "=========================================="
# Keep container alive and stream logs
tail -f /tmp/web.log /tmp/api-gateway.log 2>/dev/null || wait