Flag DSC to reboot computer if package returns a reboot code. #184
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description Of Changes
Handle package exit codes 350 and 1604 by setting $global:DSCMachineStatus = 1. DSC interprets this as a request to reboot the computer. If the LocalConfigurationManager has RebootNodeIfNeeded set, this will cause an immediate reboot after the cChocoPackageInstaller resource has returned. If RebootNodeIfNeeded is not set, DSC will stop and wait for a reboot before continuing.
Motivation and Context
To indicate that a reboot is required, a package can return a 350 or 1604 exit code when usepackagecodes is set, and that code can be percolated down through dependencies when exitwhenrebootdetected is set (see also chocolatey/choco#1038). Currently DSC doesn't know what to do with those responses. The proposed workaround in issue #25 is to use the PendingReboot resource to detect a generic reboot condition. But this is not always sufficient. For one, the reboot condition detected may not have anything to do with the cChocoPackageInstall resource. For another, a package may request a reboot but not set any of the standard Windows pending reboot flags.
In my use case, an internal third-party driver exe installer would uninstall previous instances and return a specific exit code if run when a previous version was already installed. In this case, a reboot is required and the installer must be re-run. Having built the internal Chocolatey package, I honored the specific return code from the exe installer by setting the Chocolatey return code 1604 to indicate a "some work completed prior to reboot request being detected". Because cChoco did not handle these exit codes any differently, DSC marked the resource as being in a desired state and never completed the installation even allowing the attempted installation of other dependent packages.
Testing
This has been tested internally and in production using an internal package that I do not have the rights to publish to the community repo.
Operating Systems Testing
Windows 10 LTSC
Windows 11 23H2
Change Types Made
Change Checklist
Related Issue
Fixes #25