diff --git a/functions/server/Update-Server.psm1 b/functions/server/Update-Server.psm1 index 6d32a6d..0d45385 100644 --- a/functions/server/Update-Server.psm1 +++ b/functions/server/Update-Server.psm1 @@ -56,7 +56,22 @@ function Update-Server { #Run the update String Write-ServerMsg "$UpdateType $ValidatingString $VersionString Build." try { - $Task = Start-Process $Global.SteamCMD -ArgumentList "+runscript `"$ScriptPath`"" -Wait -PassThru -NoNewWindow + $ExitCode = -1 + $Retries = 0 + while ($ExitCode -ne 0 -and $Retries -lt $Global.MaxDownloadRetries) { + $Task = Start-Process $Global.SteamCMD -ArgumentList "+runscript `"$ScriptPath`"" -Wait -PassThru -NoNewWindow + $ExitCode = $Task.ExitCode + if ($ExitCode -ne 0) { + Write-ServerMsg "SteamCMD failed to complete. Retrying..." + $Retries++ + } + else { + Write-ServerMsg "SteamCMD completed successfully." + } + } + if ($Retries -eq $Global.MaxDownloadRetries) { + Exit-WithError -ErrorMsg "SteamCMD failed to complete after $Global.MaxDownloadRetries retries." + } } catch { Exit-WithError -ErrorMsg "SteamCMD failed to complete." diff --git a/global.psm1 b/global.psm1 index 77e04e2..66a001a 100644 --- a/global.psm1 +++ b/global.psm1 @@ -46,6 +46,9 @@ $GlobalDetails = @{ #Lock Timeout in miuntes LockTimeout = 10 + + #Max download retries + MaxDownloadRetries = 5 } #Create the object