Skip to content

Commit bc7e21d

Browse files
committed
Adds support to ensure Icinga services are always set to delayed auto start
1 parent e15e940 commit bc7e21d

File tree

6 files changed

+51
-6
lines changed

6 files changed

+51
-6
lines changed

doc/100-General/10-Changelog.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,13 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
2323
* [#787](https://github.com/Icinga/icinga-powershell-framework/pull/787) Fixes the return value in case the `Agent` component could not be installed from `$FALSE` to `null`
2424
* [#796](https://github.com/Icinga/icinga-powershell-framework/issues/796) [#798](https://github.com/Icinga/icinga-powershell-framework/issues/798) Fixes an issue with the new check handling, which did not properly convert values from checks to the correct performance data values and base values in some cases
2525
* [#797](https://github.com/Icinga/icinga-powershell-framework/issues/797) Fixes plugins throwing `UNKNOWN` in case `-TresholdInterval` is used for Metrics over Time, when checks are newly registered and checked, before the first MoT is executed and collected
26+
* [#800](https://github.com/Icinga/icinga-powershell-framework/pull/800) Fixes an issue for certain plugins, like `Invoke-IcingaCheckProcess`, which reports unknown if MetricsOverTime is used for checks that do not write performance data
2627
* [#809](https://github.com/Icinga/icinga-powershell-framework/issues/809) Fixes plugin compiler not handling `AddSummaryHeader` properly for nested check packages, not adding any check information
2728

2829
### Enhancements
2930

3031
* [#810](https://github.com/Icinga/icinga-powershell-framework/pull/810) Adds support to suppress messages for `Disable-IcingaUntrustedCertificateValidation`
31-
32-
## 1.13.3 (tbd)
33-
34-
* [#800](https://github.com/Icinga/icinga-powershell-framework/pull/800) Fixes an issue for certain plugins, like `Invoke-IcingaCheckProcess`, which reports unknown if MetricsOverTime is used for checks that do not write performance data
32+
* [#812](https://github.com/Icinga/icinga-powershell-framework/pull/812) Adds new Cmdlet `Set-IcingaForWindowsServicesDelayedStart` which will update the Icinga Agent and Icinga for Windows service to run with delayed autostart
3533

3634
## 1.13.2 (2025-02-03)
3735

lib/core/framework/Install-IcingaForWindowsService.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function Install-IcingaForWindowsService()
6868
);
6969

7070
if ($IfWService.Present -eq $FALSE) {
71-
$ServiceCreation = Start-IcingaProcess -Executable 'sc.exe' -Arguments ([string]::Format('create icingapowershell binPath= "{0}" DisplayName= "Icinga PowerShell Service" start= auto', $Path));
71+
$ServiceCreation = Start-IcingaProcess -Executable 'sc.exe' -Arguments ([string]::Format('create icingapowershell binPath= "{0}" DisplayName= "Icinga PowerShell Service" start= delayed-auto', $Path));
7272
$Global:Icinga.Protected.Environment.'PowerShell Service'.Present = $TRUE;
7373
$Global:Icinga.Protected.Environment.'PowerShell Service'.User = $User;
7474
$Global:Icinga.Protected.Environment.'PowerShell Service'.ServicePath = $Path;

lib/core/framework/Invoke-IcingaForWindowsMigration.psm1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,13 @@ function Invoke-IcingaForWindowsMigration()
165165

166166
Set-IcingaForWindowsMigration -MigrationVersion (New-IcingaVersionObject -Version '1.13.0.1');
167167
}
168+
169+
if (Test-IcingaForWindowsMigration -MigrationVersion (New-IcingaVersionObject -Version '1.13.3')) {
170+
Write-IcingaConsoleNotice 'Applying pending migrations required for Icinga for Windows v1.13.3';
171+
172+
# Update the Icinga Agent and Icinga for Windows service to delayed start
173+
Set-IcingaForWindowsServicesDelayedStart;
174+
175+
Set-IcingaForWindowsMigration -MigrationVersion (New-IcingaVersionObject -Version '1.13.3');
176+
}
168177
}

lib/core/icingaagent/repair/Repair-IcingaService.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function Repair-IcingaService()
6060
-Objects $IcingaServicePath;
6161

6262
$IcingaServicePath = [string]::Format('\"{0}\" --scm \"daemon\"', $IcingaServicePath);
63-
$IcingaService = Start-IcingaProcess -Executable 'sc.exe' -Arguments ([string]::Format('create icinga2 binPath= "{0}" DisplayName= "Icinga 2" start= auto', $IcingaServicePath));
63+
$IcingaService = Start-IcingaProcess -Executable 'sc.exe' -Arguments ([string]::Format('create icinga2 binPath= "{0}" DisplayName= "Icinga 2" start= delayed-auto', $IcingaServicePath));
6464

6565
if ($IcingaService.ExitCode -ne 0) {
6666
Write-IcingaConsoleError `

lib/core/repository/Install-IcingaComponent.psm1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ function Install-IcingaComponent()
288288
[void](Install-IcingaForWindowsService -Path $ServiceBin -User $ServiceUser -Password (Get-IcingaInternalPowerShellServicePassword));
289289
Update-IcingaServiceUser;
290290
Set-IcingaInternalPowerShellServicePassword -Password $null;
291+
Set-IcingaForWindowsServicesDelayedStart;
291292
$Success = 1;
292293
break;
293294
}
@@ -405,6 +406,7 @@ function Install-IcingaComponent()
405406

406407
Set-IcingaServiceUser -User $ServiceUser -SetPermission | Out-Null;
407408
Update-IcingaServiceUser;
409+
Set-IcingaForWindowsServicesDelayedStart;
408410

409411
Write-IcingaConsoleNotice 'Installation of component "agent" with version "{0}" was successful.' -Objects $MSIData.ProductVersion;
410412
} else {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<#
2+
.SYNOPSIS
3+
Configures the Icinga services to use delayed auto-start.
4+
.DESCRIPTION
5+
The `Set-IcingaForWindowsServicesDelayedStart` function sets the startup type of the Icinga 2 and Icinga PowerShell services to "delayed-auto" using the `sc.exe` command. This ensures that the services start after other critical system services during the boot process.
6+
.EXAMPLE
7+
Set-IcingaForWindowsServicesDelayedStart
8+
9+
This example sets the Icinga 2 and Icinga PowerShell services to delayed auto-start if they are present in the environment.
10+
#>
11+
function Set-IcingaForWindowsServicesDelayedStart()
12+
{
13+
Set-IcingaServiceEnvironment;
14+
15+
$IcingaAgentService = $Global:Icinga.Protected.Environment.'Icinga Service';
16+
$IcingaForWindowsService = $Global:Icinga.Protected.Environment.'PowerShell Service';
17+
18+
if ($null -ne $IcingaAgentService -And $IcingaAgentService.Present) {
19+
$ServiceUpdate = Start-IcingaProcess -Executable 'sc.exe' -Arguments 'config icinga2 start= delayed-auto';
20+
21+
if ($ServiceUpdate.ExitCode -ne 0) {
22+
Write-IcingaConsoleError ([string]::Format('Failed to set the icinga2 service to delayed autostart: {0}', $ServiceUpdate.Message));
23+
} else {
24+
Write-IcingaConsoleNotice 'Successfully set the icinga2 service to delayed autostart';
25+
}
26+
}
27+
if ($null -ne $IcingaForWindowsService -And $IcingaForWindowsService.Present) {
28+
$ServiceUpdate = Start-IcingaProcess -Executable 'sc.exe' -Arguments 'config icingapowershell start= delayed-auto';
29+
30+
if ($ServiceUpdate.ExitCode -ne 0) {
31+
Write-IcingaConsoleError ([string]::Format('Failed to set the icingapowershell service to delayed autostart: {0}', $ServiceUpdate.Message));
32+
} else {
33+
Write-IcingaConsoleNotice 'Successfully set the icingapowershell service to delayed autostart';
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)