Skip to content

Commit bd413fc

Browse files
committed
Adds support to ensure Icinga services are always set to delayed auto start
1 parent 0ff9286 commit bd413fc

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function Set-IcingaForWindowsServicesDelayedStart()
2+
{
3+
Set-IcingaServiceEnvironment;
4+
5+
$IcingaAgentService = $Global:Icinga.Protected.Environment.'Icinga Service';
6+
$IcingaForWindowsService = $Global:Icinga.Protected.Environment.'PowerShell Service';
7+
8+
if ($null -ne $IcingaAgentService -And $IcingaAgentService.Present) {
9+
$ServiceUpdate = Start-IcingaProcess -Executable 'sc.exe' -Arguments 'config icinga2 start= delayed-auto';
10+
11+
if ($ServiceUpdate.ExitCode -ne 0) {
12+
Write-IcingaConsoleError ([string]::Format('Failed to set the icinga2 service to delayed autostart: {0}', $ServiceUpdate.Message));
13+
} else {
14+
Write-IcingaConsoleNotice 'Successfully set the icinga2 service to delayed autostart';
15+
}
16+
}
17+
if ($null -ne $IcingaForWindowsService -And $IcingaForWindowsService.Present) {
18+
$ServiceUpdate = Start-IcingaProcess -Executable 'sc.exe' -Arguments 'config icingapowershell start= delayed-auto';
19+
20+
if ($ServiceUpdate.ExitCode -ne 0) {
21+
Write-IcingaConsoleError ([string]::Format('Failed to set the icingapowershell service to delayed autostart: {0}', $ServiceUpdate.Message));
22+
} else {
23+
Write-IcingaConsoleNotice 'Successfully set the icingapowershell service to delayed autostart';
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)