Skip to content

Commit 1fba01e

Browse files
committed
Fixes an issue on which a JEA service would become orphaned
1 parent 824b8a2 commit 1fba01e

File tree

2 files changed

+60
-57
lines changed

2 files changed

+60
-57
lines changed

doc/100-General/10-Changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
1111

1212
[Issues and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/32)
1313

14+
### Bugfixes
15+
16+
* [#734](https://github.com/Icinga/icinga-powershell-framework/issues/734) Fixes a scenario on which a JEA service could become orphaned while manually stopping the Icinga for Windows service, without gracefully shutting down JEA
17+
18+
### Enhancements
19+
1420
* [#732](https://github.com/Icinga/icinga-powershell-framework/pull/732) Adds support for TLS 1.3 and improves startup response
1521

1622
## 1.12.3 (2024-04-24)

lib/daemon/Start-IcingaPowerShellDaemon.psm1

Lines changed: 54 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -17,69 +17,66 @@ function Start-IcingaForWindowsDaemon()
1717
[switch]$JEARestart = $FALSE
1818
);
1919

20-
$Global:Icinga.Protected.RunAsDaemon = [bool]$RunAsService;
21-
$Global:Icinga.Protected.JEAContext = [bool]$JEAContext;
22-
[string]$MainServicePidFile = (Join-Path -Path (Get-IcingaCacheDir) -ChildPath 'service.pid');
23-
[string]$JeaPidFile = (Join-Path -Path (Get-IcingaCacheDir) -ChildPath 'jea.pid');
24-
[string]$JeaProfile = Get-IcingaPowerShellConfig -Path 'Framework.JEAProfile';
25-
[string]$JeaPid = '';
26-
27-
if (Test-IcingaJEAServiceRunning) {
28-
Write-IcingaEventMessage -EventId 1503 -Namespace 'Framework';
29-
exit 1;
30-
}
20+
$Global:Icinga.Protected.RunAsDaemon = [bool]$RunAsService;
21+
$Global:Icinga.Protected.JEAContext = [bool]$JEAContext;
22+
[string]$MainServicePidFile = (Join-Path -Path (Get-IcingaCacheDir) -ChildPath 'service.pid');
23+
[string]$JeaPidFile = (Join-Path -Path (Get-IcingaCacheDir) -ChildPath 'jea.pid');
24+
[string]$JeaProfile = Get-IcingaPowerShellConfig -Path 'Framework.JEAProfile';
25+
[string]$JeaPid = '';
26+
27+
if ((Test-IcingaJEAServiceRunning) -eq $FALSE) {
28+
Write-IcingaFileSecure -File ($MainServicePidFile) -Value $PID;
29+
30+
if ([string]::IsNullOrEmpty($JeaProfile)) {
31+
Write-IcingaDebugMessage -Message 'Starting Icinga for Windows service without JEA context' -Objects $RunAsService, $JEARestart, $JeaProfile;
32+
33+
# Todo: Add config for active background tasks. Set it to 20 for the moment
34+
Add-IcingaThreadPool -Name 'MainPool' -MaxInstances 20;
35+
$Global:Icinga.Public.Add(
36+
'SSL',
37+
@{
38+
'Certificate' = $null;
39+
'CertFile' = $null;
40+
'CertThumbprint' = $null;
41+
'CertFilter' = $null;
42+
}
43+
);
3144

32-
Write-IcingaFileSecure -File ($MainServicePidFile) -Value $PID;
45+
New-IcingaThreadInstance -Name "Main" -ThreadPool (Get-IcingaThreadPool -Name 'MainPool') -Command 'Add-IcingaForWindowsDaemon' -Start;
46+
} else {
47+
Write-IcingaDebugMessage -Message 'Starting Icinga for Windows service inside JEA context' -Objects $RunAsService, $JEARestart, $JeaProfile;
3348

34-
if ([string]::IsNullOrEmpty($JeaProfile)) {
35-
Write-IcingaDebugMessage -Message 'Starting Icinga for Windows service without JEA context' -Objects $RunAsService, $JEARestart, $JeaProfile;
49+
& powershell.exe -NoProfile -NoLogo -ConfigurationName $JeaProfile -Command {
50+
try {
51+
Use-Icinga -Daemon;
3652

37-
# Todo: Add config for active background tasks. Set it to 20 for the moment
38-
Add-IcingaThreadPool -Name 'MainPool' -MaxInstances 20;
39-
$Global:Icinga.Public.Add(
40-
'SSL',
41-
@{
42-
'Certificate' = $null;
43-
'CertFile' = $null;
44-
'CertThumbprint' = $null;
45-
'CertFilter' = $null;
46-
}
47-
);
48-
49-
New-IcingaThreadInstance -Name "Main" -ThreadPool (Get-IcingaThreadPool -Name 'MainPool') -Command 'Add-IcingaForWindowsDaemon' -Start;
50-
} else {
51-
Write-IcingaDebugMessage -Message 'Starting Icinga for Windows service inside JEA context' -Objects $RunAsService, $JEARestart, $JeaProfile;
52-
53-
& powershell.exe -NoProfile -NoLogo -ConfigurationName $JeaProfile -Command {
54-
try {
55-
Use-Icinga -Daemon;
56-
57-
Write-IcingaFileSecure -File ($args[0]) -Value $PID;
58-
59-
$Global:Icinga.Protected.JEAContext = $TRUE;
60-
$Global:Icinga.Protected.RunAsDaemon = $TRUE;
61-
# Todo: Add config for active background tasks. Set it to 20 for the moment
62-
Add-IcingaThreadPool -Name 'MainPool' -MaxInstances 20;
63-
64-
$Global:Icinga.Public.Add(
65-
'SSL',
66-
@{
67-
'Certificate' = $null;
68-
'CertFile' = $null;
69-
'CertThumbprint' = $null;
70-
'CertFilter' = $null;
71-
}
72-
);
53+
Write-IcingaFileSecure -File ($args[0]) -Value $PID;
54+
55+
$Global:Icinga.Protected.JEAContext = $TRUE;
56+
$Global:Icinga.Protected.RunAsDaemon = $TRUE;
57+
# Todo: Add config for active background tasks. Set it to 20 for the moment
58+
Add-IcingaThreadPool -Name 'MainPool' -MaxInstances 20;
7359

74-
New-IcingaThreadInstance -Name "Main" -ThreadPool (Get-IcingaThreadPool -Name 'MainPool') -Command 'Add-IcingaForWindowsDaemon' -Start;
60+
$Global:Icinga.Public.Add(
61+
'SSL',
62+
@{
63+
'Certificate' = $null;
64+
'CertFile' = $null;
65+
'CertThumbprint' = $null;
66+
'CertFilter' = $null;
67+
}
68+
);
7569

76-
while ($TRUE) {
77-
Start-Sleep -Seconds 100;
70+
New-IcingaThreadInstance -Name "Main" -ThreadPool (Get-IcingaThreadPool -Name 'MainPool') -Command 'Add-IcingaForWindowsDaemon' -Start;
71+
72+
while ($TRUE) {
73+
Start-Sleep -Seconds 100;
74+
}
75+
} catch {
76+
Write-IcingaEventMessage -EventId 1600 -Namespace 'Framework' -ExceptionObject $_;
7877
}
79-
} catch {
80-
Write-IcingaEventMessage -EventId 1600 -Namespace 'Framework' -ExceptionObject $_;
81-
}
82-
} -Args $JeaPidFile;
78+
} -Args $JeaPidFile;
79+
}
8380
}
8481

8582
if ($JEARestart) {

0 commit comments

Comments
 (0)