Fix tray health detection and harden backend service startup
All checks were successful
CI / test (push) Successful in 7s
All checks were successful
CI / test (push) Successful in 7s
This commit is contained in:
@@ -43,7 +43,38 @@ $publishDir = Join-Path $scriptDir "service_host\publish"
|
||||
$serviceExe = Join-Path $publishDir "ScreenJob.WindowsServiceHost.exe"
|
||||
$logDir = Join-Path $scriptDir "screenjob_runs\service"
|
||||
|
||||
$existingService = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
|
||||
if ($null -ne $existingService) {
|
||||
if (-not $ForceReinstall) {
|
||||
throw "Service '$ServiceName' already exists. Re-run with -ForceReinstall to replace it."
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess($ServiceName, "Remove existing service")) {
|
||||
if ($existingService.Status -ne "Stopped") {
|
||||
Stop-Service -Name $ServiceName -Force -ErrorAction Stop
|
||||
}
|
||||
|
||||
& sc.exe delete $ServiceName | Out-Null
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Failed to delete existing service '$ServiceName' (sc.exe exit code $LASTEXITCODE)."
|
||||
}
|
||||
|
||||
$deadline = (Get-Date).AddSeconds(15)
|
||||
while ((Get-Date) -lt $deadline) {
|
||||
$stillThere = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
|
||||
if ($null -eq $stillThere) {
|
||||
break
|
||||
}
|
||||
Start-Sleep -Milliseconds 300
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess($projectFile, "Publish Windows service host")) {
|
||||
if (Test-Path -LiteralPath $serviceExe) {
|
||||
Remove-Item -LiteralPath $serviceExe -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
& $dotnetCmd.Source publish `
|
||||
$projectFile `
|
||||
-c Release `
|
||||
@@ -63,24 +94,6 @@ if (-not (Test-Path -LiteralPath $serviceExe)) {
|
||||
|
||||
$binaryPath = "`"$serviceExe`" --backend-script `"$backendScript`" --working-dir `"$scriptDir`" --log-dir `"$logDir`""
|
||||
|
||||
$existingService = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
|
||||
if ($null -ne $existingService) {
|
||||
if (-not $ForceReinstall) {
|
||||
throw "Service '$ServiceName' already exists. Re-run with -ForceReinstall to replace it."
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess($ServiceName, "Remove existing service")) {
|
||||
if ($existingService.Status -ne "Stopped") {
|
||||
Stop-Service -Name $ServiceName -Force -ErrorAction Stop
|
||||
}
|
||||
|
||||
& sc.exe delete $ServiceName | Out-Null
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Failed to delete existing service '$ServiceName' (sc.exe exit code $LASTEXITCODE)."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess($ServiceName, "Create service")) {
|
||||
New-Service `
|
||||
-Name $ServiceName `
|
||||
|
||||
Reference in New Issue
Block a user