Fixes exceptions in certain cases while trying to stop the JEA process

This commit is contained in:
Lord Hepipud 2024-02-28 11:12:46 +01:00
parent a2ba3124e5
commit e7356a71ac
4 changed files with 39 additions and 1 deletions

View file

@ -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

View file

@ -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;
}

View file

@ -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';

View file

@ -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;
}
}