restart-backend.ps1 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # 一键重启后端服务脚本
  2. Write-Host "=========================================" -ForegroundColor Cyan
  3. Write-Host "后端服务重启脚本" -ForegroundColor Cyan
  4. Write-Host "=========================================" -ForegroundColor Cyan
  5. Write-Host ""
  6. # 1. 停止现有的 Java 进程
  7. Write-Host "步骤 1: 停止现有的 Java 进程..." -ForegroundColor Yellow
  8. $javaProcesses = Get-Process | Where-Object {$_.ProcessName -like "*java*"}
  9. if ($javaProcesses) {
  10. Write-Host "找到 $($javaProcesses.Count) 个 Java 进程" -ForegroundColor Green
  11. foreach ($process in $javaProcesses) {
  12. Write-Host " - 进程 ID: $($process.Id), 启动时间: $($process.StartTime)" -ForegroundColor Gray
  13. }
  14. $confirm = Read-Host "是否停止这些进程?(Y/N)"
  15. if ($confirm -eq 'Y' -or $confirm -eq 'y') {
  16. foreach ($process in $javaProcesses) {
  17. try {
  18. Stop-Process -Id $process.Id -Force
  19. Write-Host " ✓ 已停止进程 $($process.Id)" -ForegroundColor Green
  20. } catch {
  21. Write-Host " ✗ 无法停止进程 $($process.Id): $_" -ForegroundColor Red
  22. }
  23. }
  24. } else {
  25. Write-Host "已取消停止进程" -ForegroundColor Yellow
  26. exit 0
  27. }
  28. } else {
  29. Write-Host "未找到运行中的 Java 进程" -ForegroundColor Gray
  30. }
  31. Write-Host ""
  32. # 2. 清理并重新编译
  33. Write-Host "步骤 2: 清理并重新编译项目..." -ForegroundColor Yellow
  34. Write-Host "执行命令: mvn clean install -DskipTests" -ForegroundColor Gray
  35. Write-Host ""
  36. $compileConfirm = Read-Host "是否执行编译?这可能需要几分钟 (Y/N)"
  37. if ($compileConfirm -eq 'Y' -or $compileConfirm -eq 'y') {
  38. try {
  39. mvn clean install -DskipTests
  40. if ($LASTEXITCODE -eq 0) {
  41. Write-Host ""
  42. Write-Host "✓ 编译成功!" -ForegroundColor Green
  43. } else {
  44. Write-Host ""
  45. Write-Host "✗ 编译失败,请检查错误信息" -ForegroundColor Red
  46. exit 1
  47. }
  48. } catch {
  49. Write-Host "✗ 编译过程出错: $_" -ForegroundColor Red
  50. exit 1
  51. }
  52. } else {
  53. Write-Host "已跳过编译步骤" -ForegroundColor Yellow
  54. }
  55. Write-Host ""
  56. # 3. 启动后端服务
  57. Write-Host "步骤 3: 启动后端服务..." -ForegroundColor Yellow
  58. Write-Host "执行命令: cd yudao-server && mvn spring-boot:run -Dspring-boot.run.profiles=local" -ForegroundColor Gray
  59. Write-Host ""
  60. $startConfirm = Read-Host "是否启动后端服务?(Y/N)"
  61. if ($startConfirm -eq 'Y' -or $startConfirm -eq 'y') {
  62. Write-Host ""
  63. Write-Host "正在启动后端服务..." -ForegroundColor Green
  64. Write-Host "提示: 服务启动后,请访问 http://localhost:48080/doc.html 验证" -ForegroundColor Cyan
  65. Write-Host ""
  66. Set-Location yudao-server
  67. mvn spring-boot:run -Dspring-boot.run.profiles=local
  68. } else {
  69. Write-Host ""
  70. Write-Host "已跳过启动步骤" -ForegroundColor Yellow
  71. Write-Host ""
  72. Write-Host "手动启动命令:" -ForegroundColor Cyan
  73. Write-Host " cd yudao-server" -ForegroundColor Gray
  74. Write-Host " mvn spring-boot:run -Dspring-boot.run.profiles=local" -ForegroundColor Gray
  75. }
  76. Write-Host ""
  77. Write-Host "=========================================" -ForegroundColor Cyan
  78. Write-Host "完成" -ForegroundColor Cyan
  79. Write-Host "=========================================" -ForegroundColor Cyan