$pub = "G:\WEB-SERVER\htdocs\AttendanceHub\ZKTecoSyncService-V2\publish" $stage = "G:\WEB-SERVER\htdocs\AttendanceHub\ZKTecoSyncService-V2\publish_delivery_staging" $outFile = "G:\WEB-SERVER\htdocs\AttendanceHub\ZKTecoSyncService-V2\_deployment\activation_results.txt" $r = New-Object System.Collections.Generic.List[string] $r.Add("elevatedAt=$(Get-Date -Format o)") $r.Add("---- STOP") Stop-Service ZKTecoSyncService -Force -ErrorAction SilentlyContinue $sw = [System.Diagnostics.Stopwatch]::StartNew() while ((Get-Service ZKTecoSyncService).Status -ne 'Stopped' -and $sw.Elapsed.TotalSeconds -lt 45) { Start-Sleep -Seconds 1 } $r.Add("state_after_stop=" + (Get-Service ZKTecoSyncService).Status) $svcPid = (Get-CimInstance Win32_Service -Filter "Name='ZKTecoSyncService'").ProcessId $r.Add("service_pid_after_stop=$svcPid") $leftover = @(Get-Process AttendanceHub.Sync.Host -ErrorAction SilentlyContinue) $r.Add("leftover_host_processes=" + $leftover.Count) foreach ($p in $leftover) { Stop-Process -Id $p.Id -Force; Start-Sleep -Seconds 2; $r.Add("forced_leftover_pid=$($p.Id)") } $r.Add("---- COPY staging -> publish") robocopy $stage $pub /E /IS /R:2 /W:2 /NFL /NDL /NJH /NJS | Out-Null $r.Add("robocopy_exit=$LASTEXITCODE (0-7 = success)") $r.Add("---- VERIFY hashes") $okAll = $true foreach ($n in @("AttendanceHub.Sync.Host.exe","AttendanceHub.Sync.Host.dll","AttendanceHub.Sync.dll")) { $h1 = (Get-FileHash (Join-Path $stage $n) -Algorithm SHA256).Hash $h2 = (Get-FileHash (Join-Path $pub $n) -Algorithm SHA256).Hash $m = $h1 -eq $h2 if (-not $m) { $okAll = $false } $r.Add("$n match=$m deployed=$h2") } $h1 = (Get-FileHash (Join-Path $stage "config\phase1.device.json") -Algorithm SHA256).Hash $h2 = (Get-FileHash (Join-Path $pub "config\phase1.device.json") -Algorithm SHA256).Hash $mcfg = $h1 -eq $h2 if (-not $mcfg) { $okAll = $false } $r.Add("config match=$mcfg") try { $cfg = Get-Content (Join-Path $pub "config\phase1.device.json") -Raw | ConvertFrom-Json; $r.Add("deployed_upload_enabled=$($cfg.upload.enabled) batch=$($cfg.upload.batchSize) conc=$($cfg.upload.maxConcurrency) base=$($cfg.upload.baseAddress) path=$($cfg.upload.batchPath)") } catch { $r.Add("config_parse_ERROR=$($_.Exception.Message)"); $okAll = $false } $svc = Get-CimInstance Win32_Service -Filter "Name='ZKTecoSyncService'" $expected = "`"G:\WEB-SERVER\htdocs\AttendanceHub\ZKTecoSyncService-V2\publish\AttendanceHub.Sync.Host.exe`"" $binOk = $svc.PathName -eq $expected $r.Add("binPath_unchanged=$binOk path=$($svc.PathName)") $r.Add("---- START") Start-Service ZKTecoSyncService -ErrorAction SilentlyContinue $sw2 = [System.Diagnostics.Stopwatch]::StartNew() while ((Get-Service ZKTecoSyncService).Status -ne 'Running' -and $sw2.Elapsed.TotalSeconds -lt 45) { Start-Sleep -Seconds 1 } $svc2 = Get-CimInstance Win32_Service -Filter "Name='ZKTecoSyncService'" $r.Add("state_final=" + (Get-Service ZKTecoSyncService).Status) $r.Add("pid_final=$($svc2.ProcessId)") $r.Add("all_hash_match=$okAll") Set-Content -Path $outFile -Value ($r -join "`r`n") -Encoding UTF8