59 lines
1.6 KiB
Bash
Executable File
59 lines
1.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
echo "🚀 启动多智能体任务管理系统 v2.0..."
|
|
|
|
# 配置
|
|
DB_HOST=localhost
|
|
DB_PORT=5433
|
|
DB_NAME=agent_tasks_v2
|
|
DB_PASSWORD=postgres
|
|
|
|
# 检查数据库容器
|
|
if ! docker ps | grep -q test-postgres; then
|
|
echo "❌ PostgreSQL 容器未运行"
|
|
echo "启动命令: docker run -d --name test-postgres -e POSTGRES_PASSWORD=postgres -p 5433:5432 postgres:15-alpine"
|
|
exit 1
|
|
fi
|
|
|
|
# 检查数据库是否存在
|
|
DB_EXISTS=$(docker exec test-postgres psql -U postgres -lqt | cut -d \| -f 1 | grep -w $DB_NAME | wc -l)
|
|
|
|
if [ "$DB_EXISTS" -eq 0 ]; then
|
|
echo "📦 创建数据库 $DB_NAME..."
|
|
docker exec test-postgres psql -U postgres -c "CREATE DATABASE $DB_NAME;"
|
|
|
|
echo "🔧 运行数据库迁移..."
|
|
DB_HOST=$DB_HOST DB_PORT=$DB_PORT DB_NAME=$DB_NAME DB_PASSWORD=$DB_PASSWORD node migrate.js
|
|
fi
|
|
|
|
# 停止旧服务
|
|
pkill -f "server-v2.js" 2>/dev/null
|
|
|
|
# 启动服务
|
|
echo "🎯 启动服务..."
|
|
DB_HOST=$DB_HOST \
|
|
DB_PORT=$DB_PORT \
|
|
DB_NAME=$DB_NAME \
|
|
DB_PASSWORD=$DB_PASSWORD \
|
|
nohup node server-v2.js > server-v2.log 2>&1 &
|
|
|
|
sleep 2
|
|
|
|
# 检查服务状态
|
|
if curl -s http://localhost:3000/health > /dev/null; then
|
|
echo ""
|
|
echo "✅ 服务启动成功!"
|
|
echo ""
|
|
echo "🌐 访问地址:"
|
|
echo " 本地: http://localhost:3000"
|
|
echo " 远程: http://192.168.0.250:3000"
|
|
echo ""
|
|
echo "📊 统计信息: curl http://localhost:3000/api/stats"
|
|
echo "📝 查看日志: tail -f server-v2.log"
|
|
echo "🛑 停止服务: pkill -f server-v2.js"
|
|
else
|
|
echo "❌ 服务启动失败,请查看 server-v2.log"
|
|
tail -20 server-v2.log
|
|
exit 1
|
|
fi
|