Files
erp-ass/docs/SCRIPTS_SUMMARY.md
dazhuang 344a750cfb feat: add one-click startup scripts for project management
- Add start.sh/start.bat for one-click startup (backend + frontend)
- Add stop.sh/stop.bat for stopping all services
- Add restart.sh for restarting services
- Add status.sh for checking service status
- Add Makefile with convenient management commands
- Add comprehensive documentation (ONE_CLICK_START.md)
- Update README with one-click startup instructions

Features:
- Automatic environment checking (venv, node_modules)
- Process management with PID tracking
- Unified log management (logs/*.log)
- Health checking after startup
- Support for Linux, macOS, and Windows
- No more need for multiple terminal windows

Usage:
  ./start.sh      # Start all services
  ./stop.sh       # Stop all services
  ./status.sh     # Check service status
  ./restart.sh    # Restart services
  make start      # Alternative using Makefile

Benefits:
- One command instead of multiple terminals
- Automatic environment validation
- Centralized logging
- Process lifecycle management
- Developer-friendly output messages
2026-03-22 02:49:22 +00:00

4.5 KiB
Raw Permalink Blame History

一键启动脚本创建完成

已创建的文件

Linux/Mac 脚本

  1. start.sh - 一键启动脚本

    • 自动检查依赖环境
    • 启动后端和前端服务
    • 保存进程 PID
    • 健康检查
  2. stop.sh - 停止脚本

    • 优雅停止所有进程
    • 强制清理残留进程
    • 清理 PID 文件
  3. restart.sh - 重启脚本

    • 先停止后启动
    • 等待间隔确保完全停止
  4. status.sh - 状态查看脚本

    • 检查服务运行状态
    • 显示进程信息
    • 提供日志查看命令

Windows 脚本

  1. start.bat - Windows 启动脚本

    • 在新窗口中启动服务
    • 自动检查环境
  2. stop.bat - Windows 停止脚本

    • 查找并停止进程
    • 清理端口占用

文档

  1. docs/ONE_CLICK_START.md - 详细使用指南
    • 使用方法
    • 故障排查
    • 高级用法

🎯 使用方法

首次使用

# 1. 后端配置
cd backend
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
cp .env.example .env
# 编辑 .env 填入配置

# 2. 前端配置
cd ../frontend
npm install

# 3. 添加脚本执行权限
cd ..
chmod +x *.sh

日常使用

# 启动项目
./start.sh

# 查看状态
./status.sh

# 查看日志
tail -f logs/backend.log
tail -f logs/frontend.log

# 停止项目
./stop.sh

# 重启项目
./restart.sh

📊 启动输出示例

$ ./start.sh
========================================
   ERP AI Assistant - 启动中...
========================================

启动后端服务...
  PID: 12345
  日志: /data/erp-ass/logs/backend.log
  地址: http://localhost:8000

等待后端启动...
✓ 后端启动成功

启动前端服务...
  PID: 12346
  日志: /data/erp-ass/logs/frontend.log
  地址: http://localhost:5173

等待前端启动...
✓ 前端启动成功

========================================
   ✅ 启动完成!
========================================

📍 访问地址:
   前端: http://localhost:5173
   后端: http://localhost:8000
   API文档: http://localhost:8000/docs

📋 管理命令:
   查看日志: tail -f logs/backend.log
   停止服务: ./stop.sh
   重启服务: ./restart.sh

💡 核心特性

1. 环境检查

脚本会自动检查:

  • Python 虚拟环境是否存在
  • 前端依赖是否安装
  • .env 配置文件是否存在

如果缺失,会给出明确的提示。

2. 进程管理

  • 自动清理旧进程
  • 保存进程 PID 到 logs/pids.txt
  • 支持优雅停止和强制停止

3. 日志管理

  • 后端日志: logs/backend.log
  • 前端日志: logs/frontend.log
  • 支持 tail -f 实时查看

4. 健康检查

  • 启动后自动检查服务是否正常运行
  • 后端检查: http://localhost:8000/health
  • 前端检查: http://localhost:5173

🔄 对比传统方式

传统方式(需要两个终端)

终端 1:

cd backend
source venv/bin/activate
python -m app.main

终端 2:

cd frontend
npm run dev

缺点:

  • 占用两个终端窗口
  • 需要记忆多个命令
  • 没有统一的日志管理
  • 没有进程管理

一键启动

./start.sh

优点:

  • 一个命令完成所有启动
  • 只占用一个终端
  • 自动环境检查
  • 统一日志管理
  • 进程 PID 管理
  • 健康检查
  • 友好的输出信息

🐛 已知问题和解决方案

问题 1: 权限不足

症状: bash: ./start.sh: Permission denied

解决方案:

chmod +x *.sh

问题 2: 虚拟环境路径问题

症状: 虚拟环境激活失败

解决方案: 确保在项目根目录运行脚本,或使用绝对路径。

问题 3: 端口被占用

症状: 启动失败,端口已被使用

解决方案:

# 查看端口占用
lsof -i :8000
lsof -i :5173

# 停止服务
./stop.sh

# 或手动杀进程
kill -9 <PID>

📚 下一步

  1. 测试脚本: 运行 ./start.sh 测试启动
  2. 查看状态: 运行 ./status.sh 查看服务状态
  3. 访问应用: 打开 http://localhost:5173
  4. 查看日志: tail -f logs/backend.log

🎉 总结

现在你可以通过一个命令启动整个项目了!

Linux/Mac:

  • 启动: ./start.sh
  • 停止: ./stop.sh
  • 状态: ./status.sh
  • 重启: ./restart.sh

Windows:

  • 启动: start.bat
  • 停止: stop.bat

不再需要手动打开多个终端窗口!


创建时间: 2026-03-22 文件数量: 7 个4 个 Linux/Mac 脚本 + 2 个 Windows 脚本 + 1 个文档) 所有脚本已添加执行权限