63 lines
2.3 KiB
PowerShell
63 lines
2.3 KiB
PowerShell
param(
|
|
[switch]$Apply
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
$bundle = (Resolve-Path (Join-Path $PSScriptRoot '..\server\nakama\runtime\build\index.js')).Path
|
|
$test = (Resolve-Path (Join-Path $PSScriptRoot '..\server\nakama\tests\runtime_sim_test.js')).Path
|
|
$remoteFile = '/mnt/user/appdata/void-bastion-online/nakama/modules/build/index.js'
|
|
$remoteHost = 'unraid-codex'
|
|
|
|
function Assert-LastExit([string]$step) {
|
|
if ($LASTEXITCODE -ne 0) { throw "$step fehlgeschlagen (Exitcode $LASTEXITCODE)." }
|
|
}
|
|
|
|
& node $test
|
|
Assert-LastExit 'Nakama-Simulationstest'
|
|
|
|
$localHash = (Get-FileHash -LiteralPath $bundle -Algorithm SHA256).Hash.ToLowerInvariant()
|
|
$remoteHashLine = & ssh -o BatchMode=yes $remoteHost "sha256sum $remoteFile"
|
|
Assert-LastExit 'Server-Hashprüfung'
|
|
$remoteHash = ($remoteHashLine -split '\s+')[0].ToLowerInvariant()
|
|
|
|
Write-Output "Lokal: $localHash"
|
|
Write-Output "Unraid: $remoteHash"
|
|
if ($localHash -eq $remoteHash) {
|
|
Write-Output 'Nakama ist bereits auf dem aktuellen Stand.'
|
|
exit 0
|
|
}
|
|
if (-not $Apply) {
|
|
Write-Output 'Nur geprüft. Zum Veröffentlichen erneut mit -Apply ausführen.'
|
|
exit 0
|
|
}
|
|
|
|
$stamp = Get-Date -Format 'yyyyMMdd-HHmmss'
|
|
$upload = "$remoteFile.upload-$stamp"
|
|
$backup = "$remoteFile.pre-$stamp"
|
|
|
|
& scp -o BatchMode=yes $bundle "${remoteHost}:$upload"
|
|
Assert-LastExit 'Upload'
|
|
$uploadedHashLine = & ssh -o BatchMode=yes $remoteHost "sha256sum $upload"
|
|
Assert-LastExit 'Upload-Hashprüfung'
|
|
if (($uploadedHashLine -split '\s+')[0].ToLowerInvariant() -ne $localHash) {
|
|
throw 'Upload-Hash stimmt nicht überein. Aktive Serverdatei wurde nicht verändert.'
|
|
}
|
|
|
|
& ssh -o BatchMode=yes $remoteHost "cp -p $remoteFile $backup && mv $upload $remoteFile && docker restart void-bastion-nakama"
|
|
Assert-LastExit 'Sicherung, Aktivierung oder Neustart'
|
|
|
|
$healthy = $false
|
|
for ($attempt = 1; $attempt -le 15; $attempt++) {
|
|
Start-Sleep -Seconds 2
|
|
$status = & ssh -o BatchMode=yes $remoteHost 'docker inspect -f "{{.State.Health.Status}}" void-bastion-nakama'
|
|
if ($LASTEXITCODE -eq 0 -and $status.Trim() -eq 'healthy') {
|
|
$healthy = $true
|
|
break
|
|
}
|
|
}
|
|
if (-not $healthy) {
|
|
throw "Nakama ist nach dem Neustart nicht healthy. Sicherung auf Unraid: $backup. Nicht automatisch zurückgerollt."
|
|
}
|
|
|
|
Write-Output "Nakama läuft healthy. Wiederherstellbare Sicherung: $backup"
|