Skip to content

Commit 6e2ca0d

Browse files
committed
Fixes exceptions in certain cases while trying to stop the JEA process
1 parent 173161c commit 6e2ca0d

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

lib/core/jea/Get-IcingaJEAServicePid.psm1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,9 @@ function Get-IcingaJEAServicePid()
77
$JeaPid = $JeaPid.Replace("`r`n", '').Replace("`n", '').Replace(' ', '');
88
}
99

10+
if ([string]::IsNullOrEmpty($JeaPid) -Or $JeaPid -eq '0' -Or $JeaPid -eq 0) {
11+
return $null;
12+
}
13+
1014
return $JeaPid;
1115
}

lib/core/windows/Restart-IcingaWindowsService.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function Restart-IcingaWindowsService()
55
Stop-IcingaService -Service 'icingapowershell';
66

77
if ((Test-IcingaJEAServiceRunning -JeaPid $JeaPid)) {
8-
Stop-Process -Id $JeaPid -Force;
8+
Stop-IcingaJEAProcess -JeaPid $JeaPid;
99
}
1010

1111
Restart-IcingaService -Service 'icingapowershell';
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
function Stop-IcingaJEAProcess()
2+
{
3+
param (
4+
[string]$JeaPid = $null
5+
);
6+
7+
if ([string]::IsNullOrEmpty($JeaPid)) {
8+
[string]$JeaPid = Get-IcingaJEAServicePid;
9+
}
10+
11+
if ([string]::IsNullOrEmpty($JeaPid)) {
12+
return;
13+
}
14+
15+
if ($JeaPid -eq '0' -Or $JeaPid -eq 0) {
16+
return;
17+
}
18+
19+
$JeaPowerShellProcess = Get-Process -Id $JeaPid -ErrorAction SilentlyContinue;
20+
if ($null -eq $JeaPowerShellProcess) {
21+
return;
22+
}
23+
24+
if ($JeaPowerShellProcess.ProcessName -ne 'wsmprovhost') {
25+
return;
26+
}
27+
28+
try {
29+
Stop-Process -Id $JeaPid -Force -ErrorAction Stop;
30+
} catch {
31+
Write-IcingaConsoleError 'Unable to stop the JEA process "wsmprovhost" caused by the following error: "{0}".' -Objects $_.Exception.Message;
32+
}
33+
}

0 commit comments

Comments
 (0)