Skip to content

Commit 5cd09c3

Browse files
committed
WIP
1 parent 0dd9039 commit 5cd09c3

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

lib/core/framework/Install-IcingaForWindowsService.psm1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ function Install-IcingaForWindowsService()
3939

4040
$UpdateFile = [string]::Format('{0}.update', $Path);
4141

42-
$ServiceStatus = (Get-IcingaWindowsServiceStatus -Service 'icingapowershell').Status;
42+
$ServiceStatus = Get-IcingaWindowsServiceStatus -Service 'icingapowershell';
4343

4444
if ((Test-Path $UpdateFile)) {
4545

4646
Write-IcingaConsoleNotice 'Updating Icinga PowerShell Service binary';
4747

48-
if ($ServiceStatus -eq 'Running') {
48+
if ($ServiceStatus.Status -eq 'Running') {
4949
Write-IcingaConsoleNotice 'Stopping Icinga PowerShell service';
5050
Stop-IcingaWindowsService;
5151
Start-Sleep -Seconds 1;
@@ -68,7 +68,7 @@ function Install-IcingaForWindowsService()
6868
(Get-IcingaPowerShellModuleFile)
6969
);
7070

71-
if ($null -eq $ServiceStatus) {
71+
if ($ServiceStatus.Present -eq $FALSE) {
7272
$ServiceCreation = Start-IcingaProcess -Executable 'sc.exe' -Arguments ([string]::Format('create icingapowershell binPath= "{0}" DisplayName= "Icinga PowerShell Service" start= auto', $Path));
7373

7474
if ($ServiceCreation.ExitCode -ne 0) {

lib/core/framework/New-IcingaEnvironmentVariable.psm1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ function New-IcingaEnvironmentVariable()
6868
$Global:Icinga.Protected.Add('RunAsDaemon', $FALSE);
6969
$Global:Icinga.Protected.Add('Minimal', $FALSE);
7070
$Global:Icinga.Protected.Add('ThreadName', '');
71+
$Global:Icinga.Protected.Add('IcingaServiceUser', '');
72+
$Global:Icinga.Protected.Add('IfWServiceUser', '');
7173
$Global:Icinga.Protected.Add('GarbageCollector', @{ });
7274
}
7375
}

lib/core/icingaagent/getters/Get-IcingaServiceUser.psm1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
function Get-IcingaServiceUser()
22
{
3+
if ([string]::IsNullOrEmpty($Global:Icinga.Protected.IcingaServiceUser) -eq $FALSE) {
4+
return $Global:Icinga.Protected.IcingaServiceUser;
5+
}
6+
37
$Services = Get-IcingaWindowsServiceStatus -Service 'icinga2';
48
if ($Services.Present -eq $FALSE) {
59
$Services = Get-IcingaWindowsServiceStatus -Service 'icingapowershell';
@@ -21,5 +25,7 @@ function Get-IcingaServiceUser()
2125
$ServiceUser = 'NT Authority\SYSTEM';
2226
}
2327

28+
$Global:Icinga.Protected.IcingaServiceUser = $ServiceUser;
29+
2430
return $ServiceUser;
2531
}

lib/core/icingaagent/setters/Set-IcingaAgentServiceUser.psm1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ function Set-IcingaServiceUser()
4040
Set-IcingaUserPermissions;
4141
}
4242

43+
if ($Service -eq 'icinga2') {
44+
$Global:Icinga.Protected.IcingaServiceUser = $User;
45+
} elseif ($Service -eq 'icingapowershell') {
46+
$Global:Icinga.Protected.IfWServiceUser = $User;
47+
}
48+
4349
Write-IcingaConsoleNotice 'Service User "{0}" for service "{1}" successfully updated' -Objects $User, $Service;
4450
return $TRUE;
4551
} else {

0 commit comments

Comments
 (0)