java/restart-services.ps1
liRQ 9a3ef4f1ca feat(drive): 新增Logo回收定时任务与相关功能优化
1. 新增Logo回收定时任务,实现30天未访问进入回收、7天未访问则删除的策略
2. 扩展Drive实体与DO类,新增logoLastAccessTime和logoStatus字段
3. 为wp_drive表新增logo相关字段与索引
4. 优化OpenList心跳检测逻辑,缓存Token避免重复登录
5. 重构OpenList同步逻辑,直接从根目录识别存储而非调用存储API
6. 修复UserRepository时间字段插入空值问题
7. 调整MinIO预签名URL有效期为365天
8. 优化重启脚本,支持传入加密密码参数
2026-08-31 18:04:09 +08:00

100 lines
4.0 KiB
PowerShell

# Restart script for wangpan microservices
# Usage: .\restart-services.ps1
$JASYPT_PASSWORD = "wangpan-secret-key-2024"
$BASE_DIR = Split-Path -Parent $MyInvocation.MyCommand.Path
$services = @(
@{ Name = "user-service"; Port = 8081; Jar = "wangpan-user-service\target\wangpan-user-service-1.0-SNAPSHOT.jar" },
@{ Name = "drive-service"; Port = 8082; Jar = "wangpan-drive-service\target\wangpan-drive-service-1.0-SNAPSHOT.jar" },
@{ Name = "tmdb-service"; Port = 8083; Jar = "wangpan-tmdb-service\target\wangpan-tmdb-service-1.0-SNAPSHOT.jar" },
@{ Name = "gateway"; Port = 8888; Jar = "wangpan-gateway\target\wangpan-gateway-1.0-SNAPSHOT.jar" }
)
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " Wangpan Microservices Restart" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
$env:JASYPT_ENCRYPTOR_PASSWORD = $JASYPT_PASSWORD
Write-Host "[Step 1] Checking port usage..." -ForegroundColor Yellow
foreach ($service in $services) {
$port = $service.Port
$name = $service.Name
$connections = netstat -ano | Select-String ":$port\s" | Select-String "LISTENING"
if ($connections) {
$pids = $connections | ForEach-Object { ($_ -split '\s+')[-1] } | Select-Object -Unique
foreach ($procId in $pids) {
if ($procId -match '^\d+$' -and $procId -ne '0') {
try {
$process = Get-Process -Id $procId -ErrorAction SilentlyContinue
if ($process) {
Write-Host " Killing process on port $port (PID: $procId)..." -ForegroundColor Red
Stop-Process -Id $procId -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 1
}
} catch {
Write-Host " Failed to kill PID: $procId" -ForegroundColor Red
}
}
}
} else {
Write-Host " Port $port ($name) is free" -ForegroundColor Green
}
}
Write-Host "[Step 2] Waiting for ports to release..." -ForegroundColor Yellow
Start-Sleep -Seconds 3
Write-Host "[Step 3] Starting services..." -ForegroundColor Yellow
foreach ($service in $services) {
$name = $service.Name
$port = $service.Port
$jarPath = Join-Path $BASE_DIR $service.Jar
Write-Host "Starting $name on port $port..." -ForegroundColor Cyan
if (-not (Test-Path $jarPath)) {
Write-Host " ERROR: Jar not found: $jarPath" -ForegroundColor Red
continue
}
$process = Start-Process -FilePath "java" -ArgumentList "-DJASYPT_ENCRYPTOR_PASSWORD=$JASYPT_PASSWORD", "-jar", $jarPath -WindowStyle Hidden -PassThru
if ($process) {
Write-Host " Started $name (PID: $($process.Id))" -ForegroundColor Green
} else {
Write-Host " Failed to start $name" -ForegroundColor Red
}
if ($service -ne $services[-1]) {
Start-Sleep -Seconds 5
}
}
Write-Host "[Step 4] Verifying services..." -ForegroundColor Yellow
$allRunning = $true
$maxRetries = 6
foreach ($service in $services) {
$port = $service.Port
$name = $service.Name
$started = $false
for ($i = 1; $i -le $maxRetries; $i++) {
$connections = netstat -ano | Select-String ":$port\s" | Select-String "LISTENING"
if ($connections) {
Write-Host " [OK] $name (port $port)" -ForegroundColor Green
$started = $true
break
}
Start-Sleep -Seconds 5
}
if (-not $started) {
Write-Host " [FAIL] $name (port $port) - not started after $($maxRetries * 5)s" -ForegroundColor Red
$allRunning = $false
}
}
Write-Host "========================================" -ForegroundColor Cyan
if ($allRunning) {
Write-Host "All services started successfully!" -ForegroundColor Green
Write-Host "Access: http://localhost:8888" -ForegroundColor Green
} else {
Write-Host "Some services failed to start. Check logs." -ForegroundColor Red
}
Write-Host "========================================" -ForegroundColor Cyan