Skip to content

Commit

Permalink
Revert dism.exe retry changes
Browse files Browse the repository at this point in the history
Root of the problem seems to be something else is triggering the VM to be in a state where it needs a restart, so this just leads to an infinite loop
  • Loading branch information
jpalermo committed Sep 12, 2023
1 parent bdfe39d commit 54292a2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 40 deletions.
36 changes: 13 additions & 23 deletions modules/BOSH.Disk/BOSH.Disk.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,21 @@ function Optimize-Disk {
Get-WindowsFeature |
? { $_.InstallState -eq 'Available' } |
Uninstall-WindowsFeature -Remove
$DismStatus = 0

do {
# Cleanup WinSxS folder: https://technet.microsoft.com/en-us/library/dn251565.aspx
# /LogLevel default is 3
Write-Log "Running 'Dism.exe /online /LogLevel:4 /Cleanup-Image /StartComponentCleanup /ResetBase'"
Dism.exe /online /LogLevel:4 /Cleanup-Image /StartComponentCleanup /ResetBase
$DismStatus = $LASTEXITCODE
if ($DismStatus -ne 0) {
Write-Log "Error: Running 'Dism.exe /online /LogLevel:4 /Cleanup-Image /StartComponentCleanup /ResetBase'"
Write-Log "Sleeping for 30 seconds then retrying"
Start-Sleep -Seconds 30
}
} while ($DismStatus -ne 0)
# Cleanup WinSxS folder: https://technet.microsoft.com/en-us/library/dn251565.aspx
Write-Log "Running 'Dism.exe /online /LogLevel:4 /Cleanup-Image /StartComponentCleanup /ResetBase'"
Dism.exe /online /LogLevel:4 /Cleanup-Image /StartComponentCleanup /ResetBase
if ($LASTEXITCODE -ne 0) {
Write-Log "Error: Running 'Dism.exe /online /LogLevel:4 /Cleanup-Image /StartComponentCleanup /ResetBase'"
Throw "Running 'Dism.exe /online /LogLevel:4 /Cleanup-Image /StartComponentCleanup /ResetBase' failed"
}

do {
Write-Log "Running 'Dism.exe /online /LogLevel:4 /Cleanup-Image /SPSuperseded'"
Dism.exe /online /LogLevel:4 /Cleanup-Image /SPSuperseded
$DismStatus = $LASTEXITCODE
if ($DismStatus -ne 0) {
Write-Log "Error: Running 'Dism.exe /online /LogLevel:4 /Cleanup-Image /SPSuperseded'"
Write-Log "Sleeping for 30 seconds then retrying"
Start-Sleep -Seconds 30
}
} while ($DismStatus -ne 0)
Write-Log "Running 'Dism.exe /online /LogLevel:4 /Cleanup-Image /SPSuperseded'"
Dism.exe /online /LogLevel:4 /Cleanup-Image /SPSuperseded
if ($LASTEXITCODE -ne 0) {
Write-Log "Error: Running 'Dism.exe /online /LogLevel:4 /Cleanup-Image /SPSuperseded'"
Throw "Running 'Dism.exe /online /LogLevel:4 /Cleanup-Image /SPSuperseded' failed"
}

Write-Log "Finished clean disk"
}
Expand Down
31 changes: 14 additions & 17 deletions stemcell-automation/AutomationHelpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ function PostReboot
[string]$Owner = "",
[switch]$SkipRandomPassword
)
RunQuickerDism
RunQuickerDism -IgnoreErrors $True
InstallCFCell
RunQuickerDism
RunQuickerDism -IgnoreErrors $True
CleanUpVM
RunQuickerDism
RunQuickerDism -IgnoreErrors $True
SysprepVM -Organization $Organization -Owner $Owner -SkipRandomPassword $SkipRandomPassword
RunQuickerDism
}
Expand All @@ -76,21 +76,18 @@ function RunQuickerDism {
)

Write-Log "Running Quicker Dism (that is, not executing with /ResetBase)"
$DismStatus = 0
do {
# /LogLevel default is 3
Write-Log "Running 'Dism.exe /online /LogLevel:4 /Cleanup-Image /StartComponentCleanup'"
Dism.exe /online /LogLevel:4 /Cleanup-Image /StartComponentCleanup
$DismStatus = $LASTEXITCODE
if ($DismStatus -ne 0) {
Write-Log "Error: Running 'Dism.exe /online /LogLevel:4 /Cleanup-Image /StartComponentCleanup'"
if ($IgnoreErrors) {
break
}
Write-Log "Sleeping for 30 seconds then retrying"
Start-Sleep -Seconds 30
# /LogLevel default is 3
Write-Log "Running 'Dism.exe /online /LogLevel:4 /Cleanup-Image /StartComponentCleanup'"
Dism.exe /online /LogLevel:4 /Cleanup-Image /StartComponentCleanup
if ($LASTEXITCODE -ne 0) {
Write-Log "Error: Running 'Dism.exe /online /LogLevel:4 /Cleanup-Image /StartComponentCleanup'"
if ($IgnoreErrors) {
Write-Log "Ignoring: Error: Running 'Dism.exe /online /LogLevel:4 /Cleanup-Image /StartComponentCleanup'"
}
} while ($DismStatus -ne 0)
else {
Throw "Running 'Dism.exe /online /LogLevel:4 /Cleanup-Image /StartComponentCleanup' failed"
}
}
}

function CopyPSModules
Expand Down

0 comments on commit 54292a2

Please sign in to comment.