Skip to content

Commit e50069a

Browse files
authored
Merge pull request #256 from chef-cookbooks/varunsharma5/CHEF-29540
Fix for CHEF-29540: chef_client_updater fails on Windows Server 2022 and above due to failure to restart Windows EventLog Service
2 parents 0d894f0 + 49fef79 commit e50069a

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
This file is used to list changes made in each version of the chef_client_updater cookbook.
44

5-
## 3.13.0 (2206-01-19)
5+
## 3.13.1 (2026-01-28)
6+
7+
- Fixed the issue with failure to restart Windows EventLog Service
8+
9+
## 3.13.0 (2026-01-19)
610

711
- Added license_id to resource for mixlib-install 3.14.0 support of new chef downloads api requiring license key for chef-client downloads
812

metadata.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
maintainer_email 'cookbooks@chef.io'
44
license 'Apache-2.0'
55
description 'Upgrades chef-client to specified releases'
6-
version '3.13.0'
6+
version '3.13.1'
77

88
chef_version '>= 11' if respond_to?(:chef_version) # cookstyle: disable ChefModernize/RespondToInMetadata
99

providers/default.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,14 +506,25 @@ def event_log_ps_code
506506
Where-Object Status -eq 'Running' | Select-Object -ExpandProperty Name
507507
# Attempt to preemptively stop Dependent Services
508508
$depsvcsrunning | ForEach-Object {
509-
Stop-Service -Name "$_" -Force -ErrorAction SilentlyContinue
509+
$depsvc = $_
510+
try {
511+
Stop-Service -Name "$($depsvc)" -Force -ErrorAction Stop
512+
} catch {
513+
$process='svchost.exe'
514+
$data = Get-CimInstance Win32_Process -Filter "name = '$process'" | Select-Object ProcessId, CommandLine |
515+
Where-Object {$_.CommandLine -Match "$($depsvc)"}
516+
$data = $data.ProcessId
517+
Stop-Process -Id $data -Force
518+
Start-Sleep -Seconds 3
519+
}
510520
}
511521
# Stop EventLog Service - First Politely, then Forcibly
512522
try {
513523
Stop-Service -Name 'EventLog' -Force -ErrorAction Stop
514524
} catch {
515525
$process='svchost.exe'
516-
$data = Get-CimInstance Win32_Process -Filter "name = '$process'" | Select-Object ProcessId, CommandLine | Where-Object {$_.CommandLine -Match "LocalServiceNetworkRestricted"}
526+
$data = Get-CimInstance Win32_Process -Filter "name = '$process'" | Select-Object ProcessId, CommandLine |
527+
Where-Object {$_.CommandLine -Match "LocalServiceNetworkRestricted"}
517528
$data = $data.ProcessId
518529
Stop-Process -Id $data -Force
519530
Start-Sleep -Seconds 10

spec/unit/resources/default_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
context 'when license_id is provided' do
3838
before do
3939
allow_any_instance_of(Object).to receive(:update_necessary?).and_return(false)
40-
chef_run.node.normal['chef_client_updater']['license_id'] = 'test-license-123'
40+
chef_run.node.default['chef_client_updater']['license_id'] = 'test-license-123'
4141
end
4242

4343
it 'does not log a warning about missing license_id' do

0 commit comments

Comments
 (0)