Open General-Fault opened 2 months ago
This is the simple implementation of the problem stated in issue #25. However, I am also open to adding parameters to specify which exit codes should trigger a DSC induced reboot. For example, this implementation only considers exit codes 305 and 1604 (as specified by the Chocolatey documentation as indicating reboot required to complete install/update/uninstall). It does not handle exit codes such as 3010 which may indicate install/update/uninstall is completed but reboot is required.
Without the parameter, this might be considered a breaking change as DSC configurations now may unexpectedly reboot when previously they did not. In my case, and I think in most cases, this is the preferred outcome. But I defer to the project team on that decision.
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