diff --git a/doc/100-General/10-Changelog.md b/doc/100-General/10-Changelog.md index 606144e7..c1788b54 100644 --- a/doc/100-General/10-Changelog.md +++ b/doc/100-General/10-Changelog.md @@ -14,6 +14,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic ### Bugfixes * [#683](https://github.com/Icinga/icinga-powershell-framework/pull/683) Fixes JEA installer to exclude domain from user name length check, which can easily exceed the Windows 20 digits username limit +* [#685](https://github.com/Icinga/icinga-powershell-framework/pull/685) Fixes an issue while trying to stop the JEA process in certain cases, which results in an error during installation but has no other effect on the environment * [#686](https://github.com/Icinga/icinga-powershell-framework/pull/686) Fixes certutil error handling and message output in case the icingaforwindows.pfx could not be created ### Enhancements diff --git a/lib/core/jea/Get-IcingaJEAServicePid.psm1 b/lib/core/jea/Get-IcingaJEAServicePid.psm1 index 03179f81..8df76b15 100644 --- a/lib/core/jea/Get-IcingaJEAServicePid.psm1 +++ b/lib/core/jea/Get-IcingaJEAServicePid.psm1 @@ -7,5 +7,9 @@ function Get-IcingaJEAServicePid() $JeaPid = $JeaPid.Replace("`r`n", '').Replace("`n", '').Replace(' ', ''); } + if ([string]::IsNullOrEmpty($JeaPid) -Or $JeaPid -eq '0' -Or $JeaPid -eq 0) { + return $null; + } + return $JeaPid; } diff --git a/lib/core/windows/Restart-IcingaWindowsService.psm1 b/lib/core/windows/Restart-IcingaWindowsService.psm1 index 41f4a1eb..ffcb7d13 100644 --- a/lib/core/windows/Restart-IcingaWindowsService.psm1 +++ b/lib/core/windows/Restart-IcingaWindowsService.psm1 @@ -5,7 +5,7 @@ function Restart-IcingaWindowsService() Stop-IcingaService -Service 'icingapowershell'; if ((Test-IcingaJEAServiceRunning -JeaPid $JeaPid)) { - Stop-Process -Id $JeaPid -Force; + Stop-IcingaJEAProcess -JeaPid $JeaPid; } Restart-IcingaService -Service 'icingapowershell'; diff --git a/lib/core/windows/Stop-IcingaJEAProcess.psm1 b/lib/core/windows/Stop-IcingaJEAProcess.psm1 new file mode 100644 index 00000000..8b5375cb --- /dev/null +++ b/lib/core/windows/Stop-IcingaJEAProcess.psm1 @@ -0,0 +1,33 @@ +function Stop-IcingaJEAProcess() +{ + param ( + [string]$JeaPid = $null + ); + + if ([string]::IsNullOrEmpty($JeaPid)) { + [string]$JeaPid = Get-IcingaJEAServicePid; + } + + if ([string]::IsNullOrEmpty($JeaPid)) { + return; + } + + if ($JeaPid -eq '0' -Or $JeaPid -eq 0) { + return; + } + + $JeaPowerShellProcess = Get-Process -Id $JeaPid -ErrorAction SilentlyContinue; + if ($null -eq $JeaPowerShellProcess) { + return; + } + + if ($JeaPowerShellProcess.ProcessName -ne 'wsmprovhost') { + return; + } + + try { + Stop-Process -Id $JeaPid -Force -ErrorAction Stop; + } catch { + Write-IcingaConsoleError 'Unable to stop the JEA process "wsmprovhost" caused by the following error: "{0}".' -Objects $_.Exception.Message; + } +}