124 lines
3.5 KiB
Bash
Executable File
124 lines
3.5 KiB
Bash
Executable File
#!/bin/bash
|
||
|
||
# Jingrow Local 开发环境启动脚本
|
||
set -e
|
||
|
||
echo "🚀 Starting Jingrow Local development environment..."
|
||
|
||
# 清理现有进程
|
||
cleanup_processes() {
|
||
echo "🧹 Cleaning up existing processes..."
|
||
|
||
# 停止相关进程
|
||
pkill -f "uvicorn.*jingrow.main:app" 2>/dev/null || true
|
||
pkill -f "concurrently" 2>/dev/null || true
|
||
pkill -f "dramatiq.*jingrow.services.queue" 2>/dev/null || true
|
||
pkill -f "vite" 2>/dev/null || true
|
||
|
||
# 等待进程完全停止
|
||
sleep 2
|
||
|
||
# 检查端口是否释放
|
||
if netstat -tlnp 2>/dev/null | grep -q ":9001"; then
|
||
echo "⚠️ Port 9001 still in use, force killing..."
|
||
fuser -k 9001/tcp 2>/dev/null || true
|
||
sleep 1
|
||
fi
|
||
|
||
if netstat -tlnp 2>/dev/null | grep -q ":3002"; then
|
||
echo "⚠️ Port 3002 still in use, force killing..."
|
||
fuser -k 3002/tcp 2>/dev/null || true
|
||
sleep 1
|
||
fi
|
||
|
||
echo "✅ Cleanup completed"
|
||
}
|
||
|
||
# 执行清理
|
||
cleanup_processes
|
||
|
||
# 检查 Redis 是否运行
|
||
check_redis() {
|
||
if redis-cli ping > /dev/null 2>&1; then
|
||
echo "✅ Redis is already running"
|
||
return 0
|
||
else
|
||
echo "❌ Redis is not running"
|
||
return 1
|
||
fi
|
||
}
|
||
|
||
# 启动 Redis
|
||
start_redis() {
|
||
echo "🔄 Starting Redis..."
|
||
if command -v redis-server > /dev/null 2>&1; then
|
||
# 尝试启动 Redis
|
||
redis-server ./redis.conf 2>/dev/null || {
|
||
echo "⚠️ Redis server start failed, trying alternative method..."
|
||
# 如果失败,尝试其他方式
|
||
if command -v brew > /dev/null 2>&1; then
|
||
brew services start redis
|
||
elif command -v systemctl > /dev/null 2>&1; then
|
||
sudo systemctl start redis
|
||
else
|
||
echo "❌ Cannot start Redis automatically. Please start Redis manually."
|
||
echo " You can install Redis with: brew install redis (macOS) or apt-get install redis-server (Ubuntu)"
|
||
exit 1
|
||
fi
|
||
}
|
||
|
||
# 等待 Redis 启动
|
||
sleep 2
|
||
if check_redis; then
|
||
echo "✅ Redis started successfully"
|
||
else
|
||
echo "❌ Redis failed to start"
|
||
exit 1
|
||
fi
|
||
else
|
||
echo "❌ Redis is not installed. Please install Redis first:"
|
||
echo " macOS: brew install redis"
|
||
echo " Ubuntu: sudo apt-get install redis-server"
|
||
echo " Or download from: https://redis.io/download"
|
||
exit 1
|
||
fi
|
||
}
|
||
|
||
# 检查并启动 Redis
|
||
if ! check_redis; then
|
||
start_redis
|
||
fi
|
||
|
||
# 检查 Python 依赖
|
||
echo "🔍 Checking Python dependencies..."
|
||
cd backend
|
||
if ! python3 -c "import dramatiq" 2>/dev/null; then
|
||
echo "❌ Dramatiq not installed. Installing dependencies..."
|
||
pip install "dramatiq[redis,watch]" APScheduler aiohttp aioredis
|
||
fi
|
||
|
||
# 设置环境变量
|
||
export REDIS_URL="redis://localhost:6379/0"
|
||
|
||
# 从 .env 文件加载配置(可选)
|
||
if [ -f .env ]; then
|
||
export $(grep -v '^#' .env | xargs)
|
||
fi
|
||
|
||
echo "✅ All dependencies ready"
|
||
echo "🎯 Starting services..."
|
||
|
||
# 启动所有服务
|
||
# 先从项目根目录加载通用 .env(前后端共享)
|
||
cd ..
|
||
if [ -f .env ]; then
|
||
export $(grep -v '^#' .env | xargs)
|
||
fi
|
||
concurrently \
|
||
--names "REDIS,WORKER,FRONTEND,BACKEND" \
|
||
--prefix-colors "red,blue,green,yellow" \
|
||
"echo 'Redis is running'" \
|
||
"cd backend && dramatiq jingrow.services.queue --processes 1 --threads 1" \
|
||
"cd frontend && npm run dev" \
|
||
"cd backend && uvicorn jingrow.main:app --host 0.0.0.0 --port 9001 --reload --log-level info"
|