Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flag DSC to reboot computer if package returns a reboot code. #184

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

General-Fault
Copy link

@General-Fault General-Fault commented May 16, 2024

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

  • Bug fix (non-breaking change).
  • Feature / Enhancement (non-breaking change).
  • Breaking change (fix or feature that could cause existing functionality to change).
  • Documentation changes.
  • PowerShell code changes.

Change Checklist

  • Requires a change to the documentation.
  • Documentation has been updated.
  • Tests to cover my changes, have been added.
  • All new and existing tests passed?
  • PowerShell code changes: PowerShell v2 compatibility checked?

Related Issue

Fixes #25

Handle package exit codes 350 and 1604 by setting $global:DSCMachineStatus = 1.
@General-Fault
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reboot computer if installer returns a reboot code
1 participant