rgl / packer-plugin-windows-update

Packer plugin for installing Windows updates
Mozilla Public License 2.0
299 stars 71 forks source link

On Server 2012, scheduled task does not exit `101`, rather exits `2147942501` when reboot required #130

Closed cailyoung closed 8 months ago

cailyoung commented 1 year ago

https://github.com/rgl/packer-plugin-windows-update/blob/6793f6375aa3b786be6ef36d571dc9d35f9f90de/update/provisioner.go#L279 appears to be the plumbing between the restart-required check (that uses a scheduled task under the hood) and the provisioner in order to decide what to do.

On many of our VM builds, this works fine, but on Server 2012 in particular this appears to get stuck, printing Waiting for the Windows Modules Installer to exit... to the console and logging Retryable error: Windows update script exited with non-zero exit status: 2147942501 to the log.

It looks like some error/exit code translation is going on - https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499- suggests 101 is this semaphore error that was referred to in #78 - perhaps running the task as SYSTEM causes some weird failure mode in Server 2012 specifically where the result code of the process in the scheduled task is mapped via the system error table?

Screenshot 2023-08-23 at 4 26 49 pm
cailyoung commented 1 year ago

I'm open to raising a PR for this but I'm not sure whether there's a preference to resolve this in the provisioner itself, or in the remote-end powershell scripts.

cailyoung commented 1 year ago

@rgl Sorry to ping you; I am happy to work on a PR for this but don't know if you have a preference for which layer the issue is addressed in. I could see adding another case and just accepting the 2012 return value, or I could see altering the remotely-executed PowerShell to handle Server 2012 (if possible!)

rgl commented 1 year ago

I've never experienced this problem directly, so I have no idea how/where to fix it. Maybe doing a machine reboot helps? If so, reboots are handled by the go code that is running in the host.

Please be aware that I no longer use Windows Server 2012/R2 (I only use 2019/2022).

cailyoung commented 1 year ago

A reboot clears the problem (The exit code is returned because a reboot is pending, it's just being misinterpreted during communication back to packer).

I'll work up a PR and test it out on our systems. I wish I was also no longer using Server 2012! :D

matt-richardson commented 11 months ago

@rgl - I've raised https://github.com/rgl/packer-plugin-windows-update/pull/134 to fix this issue.

Are you able to take a look and merge in if you're happ?