Files
openclaw-monitor/start.sh

77 lines
2.0 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# 龙虾舰队监控中心 - 启动脚本
set -e
PROJECT_DIR="/home/node/.openclaw/workspace/flying-hero/projects/monitoring-website"
BACKEND_DIR="$PROJECT_DIR/code/backend"
FRONTEND_DIR="$PROJECT_DIR/code/frontend"
VENV_DIR="$BACKEND_DIR/venv"
echo "🦞 启动龙虾舰队监控中心..."
# 检查虚拟环境
if [ ! -d "$VENV_DIR" ]; then
echo "📦 创建 Python 虚拟环境..."
python3 -m venv "$VENV_DIR"
echo "📦 安装依赖..."
"$VENV_DIR/bin/pip" install Django djangorestframework django-cors-headers psycopg2-binary -q
fi
# 停止旧服务
echo "📌 停止旧服务..."
pkill -f "monitoring-website.*runserver" 2>/dev/null || true
pkill -f "http.server 4000" 2>/dev/null || true
sleep 1
# 启动后端
echo "🚀 启动 Django 后端 (端口 9000)..."
cd "$BACKEND_DIR"
nohup "$VENV_DIR/bin/python" manage.py runserver 0.0.0.0:9000 > /tmp/monitoring-backend.log 2>&1 &
BACKEND_PID=$!
# 等待后端启动
sleep 3
# 启动前端
echo "🚀 启动前端服务 (端口 4000)..."
cd "$FRONTEND_DIR/build"
nohup python3 -m http.server 4000 --bind 127.0.0.1 > /tmp/monitoring-frontend.log 2>&1 &
FRONTEND_PID=$!
# 等待前端启动
sleep 2
# 测试服务
echo ""
echo "🧪 测试服务..."
if curl -s http://127.0.0.1:9000/api/agents/ > /dev/null 2>&1; then
echo "✅ 后端 API 正常"
else
echo "❌ 后端 API 异常"
fi
if curl -s http://127.0.0.1:4000/ > /dev/null 2>&1; then
echo "✅ 前端服务正常"
else
echo "❌ 前端服务异常"
fi
echo ""
echo "=========================================="
echo "✅ 龙虾舰队监控中心启动完成!"
echo "=========================================="
echo ""
echo "📌 访问地址:"
echo " 监控面板http://127.0.0.1:4000"
echo " 后端 API: http://127.0.0.1:9000/api/"
echo " API 测试http://127.0.0.1:9000/api/agents/"
echo ""
echo "📌 进程信息:"
echo " 后端 PID: $BACKEND_PID"
echo " 前端 PID: $FRONTEND_PID"
echo ""
echo "📌 停止服务:"
echo " kill $BACKEND_PID $FRONTEND_PID"
echo ""