# Persistently start inquiry ledger on 8180 via WMI. Never touch prod 8080. $ErrorActionPreference = 'Stop' $Root = 'E:\wwwroot\inquiry-new' $Www = 'E:\wwwroot' $Jar = Join-Path $Root 'jeecg-system-start-3.5.3.jar' $LogDir = Join-Path $Root 'logs' $CfgDir = Join-Path $Root 'config' $IncomingJar = 'C:\Users\ytd_extdev_0903\incoming\jeecg-system-start-3.5.3.jar' $IncomingCfg = 'C:\Users\ytd_extdev_0903\incoming\ledger-config.zip' $IncomingInner = 'C:\Users\ytd_extdev_0903\incoming\_remote_run_ledger_inner.ps1' $Java = 'C:\yutongda\tools\jdk8\bin\java.exe' New-Item -ItemType Directory -Force -Path $Root, $LogDir, $CfgDir, (Join-Path $Www 'ops') | Out-Null if (Test-Path $IncomingJar) { Copy-Item $IncomingJar $Jar -Force } if (-not (Test-Path $Jar)) { throw 'jar missing' } if (-not (Test-Path $Java)) { throw 'java missing' } if (Test-Path $IncomingCfg) { Expand-Archive -Path $IncomingCfg -DestinationPath $CfgDir -Force } if (-not (Test-Path $IncomingInner)) { throw "missing $IncomingInner" } Copy-Item $IncomingInner (Join-Path $Www 'ops\run-ledger-inner.ps1') -Force $cmd = @" @echo off cd /d E:\wwwroot\inquiry-new :loop powershell.exe -NoProfile -ExecutionPolicy Bypass -File E:\wwwroot\ops\run-ledger-inner.ps1 >> E:\wwwroot\inquiry-new\logs\stdout.log 2>> E:\wwwroot\inquiry-new\logs\stderr.log echo ledger exited, restart in 5s >> E:\wwwroot\inquiry-new\logs\stderr.log timeout /t 5 /nobreak >nul goto loop "@ $cmdPath = Join-Path $Www 'ops\run-ledger.cmd' Set-Content -Path $cmdPath -Value $cmd -Encoding ASCII Get-CimInstance Win32_Process -Filter "Name='java.exe'" | ForEach-Object { if ($_.CommandLine -and $_.CommandLine -like '*inquiry-new*jeecg-system-start*') { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue } } Get-CimInstance Win32_Process | ForEach-Object { if ($_.CommandLine -and $_.CommandLine -like '*run-ledger.cmd*') { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue } } Start-Sleep -Seconds 2 $w = Invoke-CimMethod -ClassName Win32_Process -MethodName Create -Arguments @{ CommandLine = ('cmd.exe /c "' + $cmdPath + '"') } Write-Output ("LEDGER_WMI=" + $w.ReturnValue + " pid=" + $w.ProcessId) $ok = $false for ($i = 1; $i -le 30; $i++) { Start-Sleep -Seconds 5 $listen = Get-NetTCPConnection -LocalPort 8180 -State Listen -ErrorAction SilentlyContinue | Select-Object -First 1 if (-not $listen) { Write-Output ("try=" + $i + " not listen"); continue } try { $r = Invoke-WebRequest -Uri 'http://127.0.0.1:8180/jeecgboot/sys/randomImage/wmi' -UseBasicParsing -TimeoutSec 5 Write-Output ("try=" + $i + " listen pid=" + $listen.OwningProcess + " http=" + $r.StatusCode) $ok = $true break } catch { $code = $null try { $code = $_.Exception.Response.StatusCode.value__ } catch {} Write-Output ("try=" + $i + " listen pid=" + $listen.OwningProcess + " http_code=" + $code) if ($code) { $ok = $true; break } } } if (-not $ok) { Get-Content (Join-Path $LogDir 'stdout.log') -Tail 40 -ErrorAction SilentlyContinue throw 'ledger 8180 failed to stay up' } $prod = Get-NetTCPConnection -LocalPort 8080 -State Listen -ErrorAction SilentlyContinue | Select-Object -First 1 if (-not $prod) { throw 'CRITICAL: prod 8080 down' } Write-Output 'LEDGER_WMI_OK' Write-Output ("PROD_8080_OK pid=" + $prod.OwningProcess)