| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #Requires -Version 7.0
- #Requires -RunAsAdministrator
- [CmdletBinding()]
- param(
- [Parameter(Mandatory)][string] $InstallRoot,
- [Parameter(Mandatory)][string] $DataDirectory,
- [Parameter(Mandatory)][string] $Config,
- [Parameter(Mandatory)][string] $Manifest,
- [Parameter(Mandatory)][string] $Signature,
- [Parameter(Mandatory)][string] $Archive,
- [ValidateRange(4, 90)][int] $HealthSeconds = 20
- )
- $ErrorActionPreference = 'Stop'
- $name = 'AiDopDataEdge'
- $root = (Resolve-Path -LiteralPath $InstallRoot).Path
- $publisher = Join-Path $root 'publisher.pem'
- $cfg = (Resolve-Path -LiteralPath $Config).Path
- $health = Join-Path (Resolve-Path -LiteralPath $DataDirectory).Path 'health'
- $service = Get-CimInstance -ClassName Win32_Service -Filter "Name='AiDopDataEdge'"
- if (!$service -or $service.PathName -notmatch '^"([^"]+)" --run "[^"]+"$') {
- throw 'Expected the service created by Install-EdgeService.'
- }
- $previousCommand = $service.PathName
- $previousExecutable = $Matches[1]
- $stage = & $previousExecutable --stage-release $root $publisher $Manifest $Signature $Archive
- if ($LASTEXITCODE -ne 0) { throw 'Release verification failed.' }
- $next = (Resolve-Path -LiteralPath (Join-Path $stage 'Admin.NET.DataPlatform.Edge.exe')).Path
- $releaseRoot = Join-Path $root 'releases'
- if (!$next.StartsWith($releaseRoot + [System.IO.Path]::DirectorySeparatorChar, [StringComparison]::OrdinalIgnoreCase)) {
- throw 'Staged release is outside the installation root.'
- }
- function Set-ServiceBinary([string] $Binary) {
- & sc.exe config $name 'binPath=' $Binary | Out-Null
- if ($LASTEXITCODE -ne 0) { throw 'Service binary configuration failed.' }
- }
- Stop-Service -Name $name
- try {
- $cutover = [DateTime]::UtcNow
- Set-ServiceBinary ('"{0}" --run "{1}"' -f $next, $cfg)
- Start-Service -Name $name
- $deadline = [DateTime]::UtcNow.AddSeconds($HealthSeconds)
- do {
- if ((Get-Service -Name $name).Status -eq 'Running' -and
- (Test-Path -LiteralPath $health) -and (Get-Item -LiteralPath $health).LastWriteTimeUtc -gt $cutover) {
- Write-Output ('Activated ' + $next)
- return
- }
- Start-Sleep -Milliseconds 500
- } while ([DateTime]::UtcNow -lt $deadline)
- throw 'New service version did not report health.'
- }
- catch {
- Stop-Service -Name $name -ErrorAction SilentlyContinue
- Set-ServiceBinary $previousCommand
- Start-Service -Name $name
- throw
- }
|