Skip to content

Commit eedfa3a

Browse files
committed
WIP
1 parent bf0521e commit eedfa3a

10 files changed

+107
-23
lines changed
Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,40 @@
11
function Get-IcingaWindowsServiceStatus()
22
{
33
param (
4-
[string]$Service = ''
4+
[string]$Service = '',
5+
[switch]$Force = $FALSE
56
);
67

8+
if ($Service -eq 'icinga2' -Or $Service -eq 'icingapowershell') {
9+
if ($Service -eq 'icinga2') {
10+
if ([string]::IsNullOrEmpty($Global:Icinga.Protected.IcingaServiceState) -eq $FALSE) {
11+
if ($Global:Icinga.Protected.ServiceRestartLock -And $Force -eq $FALSE) {
12+
return @{
13+
'Status' = $Global:Icinga.Protected.IcingaServiceState;
14+
'Present' = $TRUE;
15+
'Name' = $Service;
16+
'DisplayName' = $Service;
17+
};
18+
}
19+
}
20+
} elseif ($Service -eq 'icingapowershell') {
21+
if ([string]::IsNullOrEmpty($Global:Icinga.Protected.IfWServiceState) -eq $FALSE) {
22+
if ($Global:Icinga.Protected.ServiceRestartLock -And $Force -eq $FALSE) {
23+
return @{
24+
'Status' = $Global:Icinga.Protected.IfWServiceState;
25+
'Present' = $TRUE;
26+
'Name' = $Service;
27+
'DisplayName' = $Service;
28+
};
29+
}
30+
}
31+
}
32+
}
33+
734
$ServiceData = Invoke-IcingaWindowsScheduledTask -JobType 'GetWindowsService' -ObjectName $Service;
835

936
if ($ServiceData.Service.Installed -eq $FALSE) {
10-
Write-IcingaConsoleError .\certificate$ServiceData.ErrMsg;
37+
Write-IcingaConsoleError $ServiceData.ErrMsg;
1138
return @{
1239
'Status' = 'Unknown';
1340
'Present' = $FALSE;
@@ -16,5 +43,11 @@ function Get-IcingaWindowsServiceStatus()
1643
};
1744
}
1845

46+
if ($Service -eq 'icinga2') {
47+
$Global:Icinga.Protected.IcingaServiceState = $ServiceData.Service.Status;
48+
} elseif ($Service -eq 'icingapowershell') {
49+
$Global:Icinga.Protected.IfWServiceState = $ServiceData.Service.Status;
50+
}
51+
1952
return $ServiceData.Service;
2053
}

lib/core/framework/New-IcingaEnvironmentVariable.psm1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ function New-IcingaEnvironmentVariable()
7070
$Global:Icinga.Protected.Add('ThreadName', '');
7171
$Global:Icinga.Protected.Add('IcingaServiceUser', '');
7272
$Global:Icinga.Protected.Add('IfWServiceUser', '');
73+
$Global:Icinga.Protected.Add('ServiceRestartLock', $FALSE);
74+
$Global:Icinga.Protected.Add('IcingaServiceState', '');
75+
$Global:Icinga.Protected.Add('IfWServiceState', '');
7376
$Global:Icinga.Protected.Add('GarbageCollector', @{ });
7477
}
7578
}

lib/core/framework/Restart-IcingaService.psm1

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,25 @@
2121
function Restart-IcingaService()
2222
{
2323
param (
24-
$Service
24+
$Service,
25+
[switch]$Force = $FALSE
2526
);
2627

28+
if ($Global:Icinga.Protected.ServiceRestartLock -And $Force -eq $FALSE) {
29+
return;
30+
}
31+
2732
$Result = Invoke-IcingaWindowsScheduledTask -JobType 'RestartWindowsService' -ObjectName $Service;
2833

2934
if ($Result.Success -eq $FALSE) {
30-
Write-IcingaConsoleError $Result.ErrMsg
35+
Write-IcingaConsoleError $Result.ErrMsg;
3136
} else {
32-
Write-IcingaConsoleNotice $Result.Message
37+
Write-IcingaConsoleNotice $Result.Message;
38+
}
39+
40+
if ($Service -eq 'icinga2') {
41+
$Global:Icinga.Protected.IcingaServiceState = $Result.Status;
42+
} elseif ($Service -eq 'icingapowershell') {
43+
$Global:Icinga.Protected.IfWServiceState = $Result.Status;
3344
}
3445
}

lib/core/framework/Start-IcingaService.psm1

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,26 @@
2020

2121
function Start-IcingaService()
2222
{
23-
param(
24-
$Service
23+
param (
24+
$Service,
25+
[switch]$Force = $FALSE
2526
);
2627

28+
if ($Global:Icinga.Protected.ServiceRestartLock -And $Force -eq $FALSE) {
29+
return;
30+
}
31+
2732
$Result = Invoke-IcingaWindowsScheduledTask -JobType 'StartWindowsService' -ObjectName $Service;
2833

2934
if ($Result.Success -eq $FALSE) {
30-
Write-IcingaConsoleError $Result.ErrMsg
35+
Write-IcingaConsoleError $Result.ErrMsg;
3136
} else {
32-
Write-IcingaConsoleNotice $Result.Message
37+
Write-IcingaConsoleNotice $Result.Message;
38+
}
39+
40+
if ($Service -eq 'icinga2') {
41+
$Global:Icinga.Protected.IcingaServiceState = $Result.Status;
42+
} elseif ($Service -eq 'icingapowershell') {
43+
$Global:Icinga.Protected.IfWServiceState = $Result.Status;
3344
}
3445
}

lib/core/framework/Stop-IcingaService.psm1

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,26 @@
2020

2121
function Stop-IcingaService()
2222
{
23-
param(
24-
$Service
23+
param (
24+
$Service,
25+
[switch]$Force = $FALSE
2526
);
2627

28+
if ($Global:Icinga.Protected.ServiceRestartLock -And $Force -eq $FALSE) {
29+
return;
30+
}
31+
2732
$Result = Invoke-IcingaWindowsScheduledTask -JobType 'StopWindowsService' -ObjectName $Service;
2833

2934
if ($Result.Success -eq $FALSE) {
30-
Write-IcingaConsoleError $Result.ErrMsg
35+
Write-IcingaConsoleError $Result.ErrMsg;
3136
} else {
32-
Write-IcingaConsoleNotice $Result.Message
37+
Write-IcingaConsoleNotice $Result.Message;
38+
}
39+
40+
if ($Service -eq 'icinga2') {
41+
$Global:Icinga.Protected.IcingaServiceState = $Result.Status;
42+
} elseif ($Service -eq 'icingapowershell') {
43+
$Global:Icinga.Protected.IfWServiceState = $Result.Status;
3344
}
3445
}

lib/core/icingaagent/misc/Start-IcingaAgentInstallWizard.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ function Start-IcingaAgentInstallWizard()
754754
if ($InstallFrameworkService) {
755755
Restart-IcingaForWindows;
756756
}
757-
Restart-IcingaService 'icinga2';
757+
Restart-IcingaService 'icinga2' -Force;
758758
}
759759
}
760760
}

lib/core/installer/Install-Icinga.psm1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ function Install-Icinga()
1313
# Always ensure we use the proper TLS Version
1414
Set-IcingaTLSVersion;
1515

16+
$Global:Icinga.Protected.ServiceRestartLock = $TRUE;
17+
1618
# Ignore SSL validation in case we set the flag
1719
if ($NoSSLValidation) {
1820
Enable-IcingaUntrustedCertificateValidation;
@@ -68,6 +70,7 @@ function Install-Icinga()
6870
$JsonInstallCmd = ConvertFrom-Json -InputObject $InstallCommand -ErrorAction Stop;
6971
} catch {
7072
Write-IcingaConsoleError 'Failed to deserialize the provided JSON from file or command: {0}' -Objects $_.Exception.Message;
73+
$Global:Icinga.Protected.ServiceRestartLock = $FALSE;
7174
return;
7275
}
7376

@@ -81,6 +84,7 @@ function Install-Icinga()
8184
$Success = Invoke-IcingaForWindowsManagementConsoleCustomConfig -IcingaConfiguration $IcingaConfiguration;
8285

8386
if ($Success -eq $FALSE) {
87+
$Global:Icinga.Protected.ServiceRestartLock = $FALSE;
8488
return;
8589
}
8690

@@ -101,6 +105,7 @@ function Install-Icinga()
101105
$Success = Invoke-IcingaForWindowsManagementConsoleCustomConfig -IcingaConfiguration $IcingaConfiguration;
102106

103107
if ($Success -eq $FALSE) {
108+
$Global:Icinga.Protected.ServiceRestartLock = $FALSE;
104109
return;
105110
}
106111

@@ -111,7 +116,7 @@ function Install-Icinga()
111116
# Set our "old" swap live again. By doing so, we can still continue our old
112117
# configuration
113118
Set-IcingaPowerShellConfig -Path 'Framework.Config.Swap' -Value $OldConfigSwap;
114-
119+
$Global:Icinga.Protected.ServiceRestartLock = $FALSE;
115120
return;
116121
}
117122

@@ -186,6 +191,8 @@ function Install-Icinga()
186191
}
187192
}
188193

194+
$Global:Icinga.Protected.ServiceRestartLock = $FALSE;
195+
189196
if ($null -ne (Get-Command -Name 'Set-IcingaForWindowsManagementConsoleClosing' -ErrorAction SilentlyContinue)) {
190197
Set-IcingaForWindowsManagementConsoleClosing -Completed;
191198
}

lib/core/installer/menu/manage/settings/services/ManageServices.psm1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function Show-IcingaForWindowsMenuManageIcingaForWindowsServices()
2525
'AdminMenu' = $TRUE;
2626
'Action' = @{
2727
'Command' = 'Start-IcingaService';
28-
'Arguments' = @{ '-Service' = 'icinga2'; };
28+
'Arguments' = @{ '-Service' = 'icinga2'; '-Force' = $TRUE; };
2929
}
3030
},
3131
@{
@@ -37,7 +37,7 @@ function Show-IcingaForWindowsMenuManageIcingaForWindowsServices()
3737
'AdminMenu' = $TRUE;
3838
'Action' = @{
3939
'Command' = 'Stop-IcingaService';
40-
'Arguments' = @{ '-Service' = 'icinga2'; };
40+
'Arguments' = @{ '-Service' = 'icinga2'; '-Force' = $TRUE; };
4141
}
4242
},
4343
@{
@@ -49,7 +49,7 @@ function Show-IcingaForWindowsMenuManageIcingaForWindowsServices()
4949
'AdminMenu' = $TRUE;
5050
'Action' = @{
5151
'Command' = 'Restart-IcingaService';
52-
'Arguments' = @{ '-Service' = 'icinga2'; };
52+
'Arguments' = @{ '-Service' = 'icinga2'; '-Force' = $TRUE; };
5353
}
5454
},
5555
@{
@@ -72,7 +72,7 @@ function Show-IcingaForWindowsMenuManageIcingaForWindowsServices()
7272
'AdminMenu' = $TRUE;
7373
'Action' = @{
7474
'Command' = 'Start-IcingaService';
75-
'Arguments' = @{ '-Service' = 'icingapowershell'; };
75+
'Arguments' = @{ '-Service' = 'icingapowershell'; '-Force' = $TRUE; };
7676
}
7777
},
7878
@{
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
function Restart-IcingaForWindows()
22
{
3+
param (
4+
[switch]$Force = $FALSE
5+
);
6+
7+
if ($Global:Icinga.Protected.ServiceRestartLock -And $Force -eq $FALSE) {
8+
return;
9+
}
10+
311
[string]$JeaPid = Get-IcingaJEAServicePid;
412

5-
Stop-IcingaService -Service 'icingapowershell';
13+
Stop-IcingaService -Service 'icingapowershell' -Force:$Force;
614

715
if ((Test-IcingaJEAServiceRunning -JeaPid $JeaPid)) {
816
Stop-IcingaJEAProcess -JeaPid $JeaPid;
917
}
1018

11-
Restart-IcingaService -Service 'icingapowershell';
19+
Restart-IcingaService -Service 'icingapowershell' -Force:$Force;
1220
}
1321

1422
Set-Alias -Name 'Restart-IcingaWindowsService' -Value 'Restart-IcingaForWindows';

lib/core/windows/Uninstall-IcingaServiceUser.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ function Uninstall-IcingaServiceUser()
1111

1212
Write-IcingaConsoleNotice 'Uninstalling user "{0}"' -Objects $IcingaUser;
1313

14-
Stop-IcingaService 'icinga2';
15-
Stop-IcingaWindowsService;
14+
Stop-IcingaService 'icinga2' -Force;
15+
Stop-IcingaWindowsService -Force;
1616

1717
Set-IcingaPowerShellConfig -Path 'Framework.Icinga.ServiceUser' -Value '';
1818

0 commit comments

Comments
 (0)