start.ps1 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. # One-click: Maven build -> copy JARs/SQL -> docker compose up (frontend + all backend)
  2. param(
  3. [switch]$SkipBuild,
  4. [switch]$NoImageBuild,
  5. [switch]$ResetDb,
  6. [switch]$Rebuild,
  7. [switch]$WithVendorSdk
  8. )
  9. if ($Rebuild) { $NoImageBuild = $false }
  10. $ErrorActionPreference = "Stop"
  11. $DockerDir = $PSScriptRoot
  12. $BackendRoot = Join-Path $DockerDir ".."
  13. function Test-DockerRunning {
  14. if (-not (Get-Command docker -ErrorAction SilentlyContinue)) {
  15. throw "Docker not found. Install Docker Desktop."
  16. }
  17. docker info 2>&1 | Out-Null
  18. if ($LASTEXITCODE -ne 0) {
  19. throw "Docker is not running. Start Docker Desktop first."
  20. }
  21. }
  22. Write-Host ""
  23. Write-Host "========================================" -ForegroundColor Cyan
  24. Write-Host " YunYan Video Monitor - One Click Start" -ForegroundColor Cyan
  25. Write-Host " Frontend (Nginx) + All Backend Services" -ForegroundColor Cyan
  26. Write-Host "========================================" -ForegroundColor Cyan
  27. Write-Host ""
  28. Test-DockerRunning
  29. if ($ResetDb) {
  30. Write-Host "[1/4] Reset MySQL data volume..." -ForegroundColor Yellow
  31. $mysqlData = Join-Path $DockerDir "mysql\data"
  32. if (Test-Path $mysqlData) {
  33. Remove-Item $mysqlData -Recurse -Force
  34. Write-Host " Removed mysql\data" -ForegroundColor Yellow
  35. }
  36. } else {
  37. Write-Host "[1/4] Skip DB reset (use -ResetDb to re-init)" -ForegroundColor DarkGray
  38. }
  39. if (-not $SkipBuild) {
  40. Write-Host "[2/4] Maven build all backend modules..." -ForegroundColor Green
  41. if (-not (Get-Command mvn -ErrorAction SilentlyContinue)) {
  42. throw "mvn not found. Install JDK 17 and Maven."
  43. }
  44. Push-Location $BackendRoot
  45. try {
  46. mvn clean package -DskipTests -T 1C
  47. if ($LASTEXITCODE -ne 0) { throw "Maven build failed" }
  48. } finally {
  49. Pop-Location
  50. }
  51. } else {
  52. Write-Host "[2/4] Skip Maven (-SkipBuild)" -ForegroundColor DarkGray
  53. }
  54. Write-Host "[3/4] Copy JARs and SQL..." -ForegroundColor Green
  55. & (Join-Path $DockerDir "copy.ps1") -SkipBuild
  56. if ($LASTEXITCODE -ne 0) { throw "copy.ps1 failed" }
  57. Write-Host "[4/4] Docker compose up (build images)..." -ForegroundColor Green
  58. Push-Location $DockerDir
  59. try {
  60. New-Item -ItemType Directory -Force -Path (Join-Path $DockerDir "ruoyi\uploadPath") | Out-Null
  61. $composeArgs = @("compose", "--env-file", ".env", "up", "-d")
  62. if (-not $NoImageBuild) {
  63. $composeArgs += "--build"
  64. }
  65. if ($WithVendorSdk) {
  66. $composeArgs += "--profile"
  67. $composeArgs += "vendor-sdk"
  68. Write-Host " vendor-sdk: Hikvision/Dahua (requires vendor .so/.dll under ruoyi-modules/*/lib)" -ForegroundColor Yellow
  69. } else {
  70. Write-Host " Default: skip Hikvision/Dahua SDK containers (no native libs in image)." -ForegroundColor DarkGray
  71. }
  72. & docker @composeArgs
  73. if ($LASTEXITCODE -ne 0) { throw "docker compose failed" }
  74. Write-Host ""
  75. Write-Host "Waiting for core services (60-120s)..." -ForegroundColor Yellow
  76. $deadline = (Get-Date).AddMinutes(8)
  77. $ready = $false
  78. while ((Get-Date) -lt $deadline) {
  79. $nacos = docker inspect --format='{{.State.Health.Status}}' ruoyi-nacos 2>$null
  80. $gw = docker inspect --format='{{.State.Status}}' ruoyi-gateway 2>$null
  81. $ngx = docker inspect --format='{{.State.Status}}' ruoyi-nginx 2>$null
  82. if ($nacos -eq "healthy" -and $gw -eq "running" -and $ngx -eq "running") {
  83. $ready = $true
  84. break
  85. }
  86. Start-Sleep -Seconds 5
  87. Write-Host " ... nacos=$nacos gateway=$gw nginx=$ngx" -ForegroundColor DarkGray
  88. }
  89. } finally {
  90. Pop-Location
  91. }
  92. Write-Host ""
  93. Write-Host "========================================" -ForegroundColor Green
  94. if ($ready) {
  95. Write-Host " Ready" -ForegroundColor Green
  96. } else {
  97. Write-Host " Containers started; some may still be booting" -ForegroundColor Yellow
  98. Write-Host " Check: docker compose ps" -ForegroundColor Yellow
  99. }
  100. Write-Host "========================================" -ForegroundColor Green
  101. Write-Host " Web UI : http://localhost"
  102. Write-Host " Gateway : http://localhost:8080"
  103. Write-Host " Nacos : http://localhost:8848/nacos"
  104. Write-Host " Login : admin / admin123"
  105. Write-Host ""
  106. Write-Host " Stop : .\stop.ps1"
  107. Write-Host " Restart : .\start.ps1 -SkipBuild -NoImageBuild"
  108. Write-Host " Hik/Dahua: .\start.ps1 -WithVendorSdk (Windows native SDK only)"
  109. Write-Host "========================================"
  110. Write-Host ""