mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2026-02-11 14:53:06 -05:00
Adds feature to offload service and JEA actions to scheduled tasks
This commit is contained in:
parent
117d20f6e6
commit
0b1de9e9c0
34 changed files with 246 additions and 177 deletions
|
|
@ -0,0 +1,8 @@
|
|||
function Clear-IcingaInternalServiceInformation()
|
||||
{
|
||||
$Global:Icinga.Protected.ServiceRestartLock = $FALSE;
|
||||
$Global:Icinga.Protected.IcingaServiceUser = '';
|
||||
$Global:Icinga.Protected.IfWServiceUser = '';
|
||||
$Global:Icinga.Protected.IcingaServiceState = '';
|
||||
$Global:Icinga.Protected.IfWServiceState = '';
|
||||
}
|
||||
53
lib/core/framework/Get-IcingaWindowsServiceStatus.psm1
Normal file
53
lib/core/framework/Get-IcingaWindowsServiceStatus.psm1
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
function Get-IcingaWindowsServiceStatus()
|
||||
{
|
||||
param (
|
||||
[string]$Service = '',
|
||||
[switch]$Force = $FALSE
|
||||
);
|
||||
|
||||
if ($Service -eq 'icinga2' -Or $Service -eq 'icingapowershell') {
|
||||
if ($Service -eq 'icinga2') {
|
||||
if ([string]::IsNullOrEmpty($Global:Icinga.Protected.IcingaServiceState) -eq $FALSE) {
|
||||
if ($Global:Icinga.Protected.ServiceRestartLock -And $Force -eq $FALSE) {
|
||||
return @{
|
||||
'Status' = $Global:Icinga.Protected.IcingaServiceState;
|
||||
'Present' = $TRUE;
|
||||
'Name' = $Service;
|
||||
'DisplayName' = $Service;
|
||||
};
|
||||
}
|
||||
}
|
||||
} elseif ($Service -eq 'icingapowershell') {
|
||||
if ([string]::IsNullOrEmpty($Global:Icinga.Protected.IfWServiceState) -eq $FALSE) {
|
||||
if ($Global:Icinga.Protected.ServiceRestartLock -And $Force -eq $FALSE) {
|
||||
return @{
|
||||
'Status' = $Global:Icinga.Protected.IfWServiceState;
|
||||
'Present' = $TRUE;
|
||||
'Name' = $Service;
|
||||
'DisplayName' = $Service;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ServiceData = Invoke-IcingaWindowsScheduledTask -JobType 'GetWindowsService' -ObjectName $Service;
|
||||
|
||||
if ($ServiceData.Service.Installed -eq $FALSE) {
|
||||
Write-IcingaConsoleError $ServiceData.ErrMsg;
|
||||
return @{
|
||||
'Status' = '';
|
||||
'Present' = $FALSE;
|
||||
'Name' = 'Unknown';
|
||||
'DisplayName' = 'Unknown';
|
||||
};
|
||||
}
|
||||
|
||||
if ($Service -eq 'icinga2') {
|
||||
$Global:Icinga.Protected.IcingaServiceState = $ServiceData.Service.Status;
|
||||
} elseif ($Service -eq 'icingapowershell') {
|
||||
$Global:Icinga.Protected.IfWServiceState = $ServiceData.Service.Status;
|
||||
}
|
||||
|
||||
return $ServiceData.Service;
|
||||
}
|
||||
|
|
@ -39,13 +39,13 @@ function Install-IcingaForWindowsService()
|
|||
|
||||
$UpdateFile = [string]::Format('{0}.update', $Path);
|
||||
|
||||
$ServiceStatus = (Get-Service 'icingapowershell' -ErrorAction SilentlyContinue).Status;
|
||||
$ServiceStatus = Get-IcingaWindowsServiceStatus -Service 'icingapowershell';
|
||||
|
||||
if ((Test-Path $UpdateFile)) {
|
||||
|
||||
Write-IcingaConsoleNotice 'Updating Icinga PowerShell Service binary';
|
||||
|
||||
if ($ServiceStatus -eq 'Running') {
|
||||
if ($ServiceStatus.Status -eq 'Running') {
|
||||
Write-IcingaConsoleNotice 'Stopping Icinga PowerShell service';
|
||||
Stop-IcingaWindowsService;
|
||||
Start-Sleep -Seconds 1;
|
||||
|
|
@ -68,7 +68,7 @@ function Install-IcingaForWindowsService()
|
|||
(Get-IcingaPowerShellModuleFile)
|
||||
);
|
||||
|
||||
if ($null -eq $ServiceStatus) {
|
||||
if ($ServiceStatus.Present -eq $FALSE) {
|
||||
$ServiceCreation = Start-IcingaProcess -Executable 'sc.exe' -Arguments ([string]::Format('create icingapowershell binPath= "{0}" DisplayName= "Icinga PowerShell Service" start= auto', $Path));
|
||||
|
||||
if ($ServiceCreation.ExitCode -ne 0) {
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ function Install-IcingaFrameworkComponent()
|
|||
|
||||
if ([string]::IsNullOrEmpty((Get-IcingaJEAContext)) -eq $FALSE) {
|
||||
Write-IcingaConsoleNotice 'Updating Icinga JEA profile';
|
||||
& powershell.exe -Command { Use-Icinga -Minimal; Install-IcingaJEAProfile; } | Out-Null;
|
||||
Invoke-IcingaWindowsScheduledTask -JobType InstallJEA -Timeout 600 | Out-Null;
|
||||
}
|
||||
|
||||
# Unload the module if it was loaded before
|
||||
|
|
|
|||
|
|
@ -52,8 +52,8 @@ function Install-IcingaFrameworkUpdate()
|
|||
|
||||
Write-IcingaConsoleNotice ([string]::Format('Using content of folder "{0}" for updates', $ModuleContent));
|
||||
|
||||
$ServiceStatus = (Get-Service 'icingapowershell' -ErrorAction SilentlyContinue).Status;
|
||||
$AgentStatus = (Get-Service 'icinga2' -ErrorAction SilentlyContinue).Status;
|
||||
$ServiceStatus = (Get-IcingaWindowsServiceStatus -Service 'icingapowershell').Status;
|
||||
$AgentStatus = (Get-IcingaWindowsServiceStatus -Service 'icinga2').Status;
|
||||
|
||||
if ($ServiceStatus -eq 'Running') {
|
||||
Write-IcingaConsoleNotice 'Stopping Icinga PowerShell service';
|
||||
|
|
@ -109,7 +109,7 @@ function Install-IcingaFrameworkUpdate()
|
|||
if ([string]::IsNullOrEmpty((Get-IcingaJEAContext)) -eq $FALSE) {
|
||||
Remove-IcingaFrameworkDependencyFile;
|
||||
Write-IcingaConsoleNotice 'Updating Icinga JEA profile';
|
||||
& powershell.exe -Command { Use-Icinga -Minimal; Install-IcingaJEAProfile; } | Out-Null;
|
||||
Invoke-IcingaWindowsScheduledTask -JobType InstallJEA -Timeout 600 | Out-Null;
|
||||
}
|
||||
|
||||
Write-IcingaConsoleNotice 'Framework update has been completed. Please start a new PowerShell instance now to complete the update';
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ function Invoke-IcingaForWindowsMigration()
|
|||
|
||||
# Upgrade to v1.8.0
|
||||
if (Test-IcingaForWindowsMigration -MigrationVersion (New-IcingaVersionObject -Version '1.8.0')) {
|
||||
$ServiceStatus = (Get-Service 'icingapowershell' -ErrorAction SilentlyContinue).Status;
|
||||
$ServiceStatus = (Get-IcingaWindowsServiceStatus -Service 'icingapowershell').Status;
|
||||
|
||||
Write-IcingaConsoleNotice 'Applying pending migrations required for Icinga for Windows v1.8.0';
|
||||
if ($ServiceStatus -eq 'Running') {
|
||||
|
|
@ -43,7 +43,7 @@ function Invoke-IcingaForWindowsMigration()
|
|||
if (Test-IcingaForWindowsMigration -MigrationVersion (New-IcingaVersionObject -Version '1.10.0')) {
|
||||
Write-IcingaConsoleNotice 'Applying pending migrations required for Icinga for Windows v1.10.0';
|
||||
|
||||
$ServiceStatus = (Get-Service 'icingapowershell' -ErrorAction SilentlyContinue).Status;
|
||||
$ServiceStatus = (Get-IcingaWindowsServiceStatus -Service 'icingapowershell').Status;
|
||||
|
||||
if ($ServiceStatus -eq 'Running') {
|
||||
Stop-IcingaWindowsService;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ function Invoke-IcingaInternalServiceCall()
|
|||
}
|
||||
|
||||
# Test our Icinga for Windows service. If the service is not installed or not running, execute the plugin locally
|
||||
$IcingaForWindowsService = (Get-Service 'icingapowershell' -ErrorAction SilentlyContinue);
|
||||
$IcingaForWindowsService = Get-Service 'icingapowershell' -ErrorAction SilentlyContinue;
|
||||
|
||||
if ($null -eq $IcingaForWindowsService -Or $IcingaForWindowsService.Status -ne 'Running') {
|
||||
return $NULL;
|
||||
|
|
|
|||
|
|
@ -68,6 +68,11 @@ function New-IcingaEnvironmentVariable()
|
|||
$Global:Icinga.Protected.Add('RunAsDaemon', $FALSE);
|
||||
$Global:Icinga.Protected.Add('Minimal', $FALSE);
|
||||
$Global:Icinga.Protected.Add('ThreadName', '');
|
||||
$Global:Icinga.Protected.Add('IcingaServiceUser', '');
|
||||
$Global:Icinga.Protected.Add('IfWServiceUser', '');
|
||||
$Global:Icinga.Protected.Add('ServiceRestartLock', $FALSE);
|
||||
$Global:Icinga.Protected.Add('IcingaServiceState', '');
|
||||
$Global:Icinga.Protected.Add('IfWServiceState', '');
|
||||
$Global:Icinga.Protected.Add('GarbageCollector', @{ });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,27 +21,25 @@
|
|||
function Restart-IcingaService()
|
||||
{
|
||||
param (
|
||||
$Service
|
||||
$Service,
|
||||
[switch]$Force = $FALSE
|
||||
);
|
||||
|
||||
if (Get-Service "$Service" -ErrorAction SilentlyContinue) {
|
||||
Write-IcingaConsoleNotice ([string]::Format('Restarting service "{0}"', $Service));
|
||||
|
||||
& powershell.exe -Command {
|
||||
Use-Icinga -Minimal;
|
||||
|
||||
$Service = $args[0];
|
||||
try {
|
||||
Restart-Service "$Service" -ErrorAction Stop;
|
||||
Start-Sleep -Seconds 2;
|
||||
Optimize-IcingaForWindowsMemory;
|
||||
} catch {
|
||||
Write-IcingaConsoleError -Message 'Failed to restart service "{0}". Error: {1}' -Objects $Service, $_.Exception.Message;
|
||||
}
|
||||
} -Args $Service;
|
||||
} else {
|
||||
Write-IcingaConsoleWarning -Message 'The service "{0}" is not installed' -Objects $Service;
|
||||
if ($Global:Icinga.Protected.ServiceRestartLock -And $Force -eq $FALSE) {
|
||||
return;
|
||||
}
|
||||
|
||||
Optimize-IcingaForWindowsMemory;
|
||||
$Result = Invoke-IcingaWindowsScheduledTask -JobType 'RestartWindowsService' -ObjectName $Service;
|
||||
|
||||
if ($Result.Success -eq $FALSE) {
|
||||
Write-IcingaConsoleError $Result.ErrMsg;
|
||||
} else {
|
||||
Write-IcingaConsoleNotice $Result.Message;
|
||||
}
|
||||
|
||||
if ($Service -eq 'icinga2') {
|
||||
$Global:Icinga.Protected.IcingaServiceState = $Result.Status;
|
||||
} elseif ($Service -eq 'icingapowershell') {
|
||||
$Global:Icinga.Protected.IfWServiceState = $Result.Status;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,28 +20,26 @@
|
|||
|
||||
function Start-IcingaService()
|
||||
{
|
||||
param(
|
||||
$Service
|
||||
param (
|
||||
$Service,
|
||||
[switch]$Force = $FALSE
|
||||
);
|
||||
|
||||
if (Get-Service $Service -ErrorAction SilentlyContinue) {
|
||||
Write-IcingaConsoleNotice -Message 'Starting service "{0}"' -Objects $Service;
|
||||
|
||||
& powershell.exe -Command {
|
||||
Use-Icinga -Minimal;
|
||||
|
||||
$Service = $args[0];
|
||||
try {
|
||||
Start-Service "$Service" -ErrorAction Stop;
|
||||
Start-Sleep -Seconds 2;
|
||||
Optimize-IcingaForWindowsMemory;
|
||||
} catch {
|
||||
Write-IcingaConsoleError -Message 'Failed to start service "{0}". Error: {1}' -Objects $Service, $_.Exception.Message;
|
||||
}
|
||||
} -Args $Service;
|
||||
} else {
|
||||
Write-IcingaConsoleWarning -Message 'The service "{0}" is not installed' -Objects $Service;
|
||||
if ($Global:Icinga.Protected.ServiceRestartLock -And $Force -eq $FALSE) {
|
||||
return;
|
||||
}
|
||||
|
||||
Optimize-IcingaForWindowsMemory;
|
||||
$Result = Invoke-IcingaWindowsScheduledTask -JobType 'StartWindowsService' -ObjectName $Service;
|
||||
|
||||
if ($Result.Success -eq $FALSE) {
|
||||
Write-IcingaConsoleError $Result.ErrMsg;
|
||||
} else {
|
||||
Write-IcingaConsoleNotice $Result.Message;
|
||||
}
|
||||
|
||||
if ($Service -eq 'icinga2') {
|
||||
$Global:Icinga.Protected.IcingaServiceState = $Result.Status;
|
||||
} elseif ($Service -eq 'icingapowershell') {
|
||||
$Global:Icinga.Protected.IfWServiceState = $Result.Status;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,28 +20,26 @@
|
|||
|
||||
function Stop-IcingaService()
|
||||
{
|
||||
param(
|
||||
$Service
|
||||
param (
|
||||
$Service,
|
||||
[switch]$Force = $FALSE
|
||||
);
|
||||
|
||||
if (Get-Service "$Service" -ErrorAction SilentlyContinue) {
|
||||
Write-IcingaConsoleNotice -Message 'Stopping service "{0}"' -Objects $Service;
|
||||
|
||||
& powershell.exe -Command {
|
||||
Use-Icinga -Minimal;
|
||||
|
||||
$Service = $args[0];
|
||||
try {
|
||||
Stop-Service "$Service" -ErrorAction Stop;
|
||||
Start-Sleep -Seconds 2;
|
||||
Optimize-IcingaForWindowsMemory;
|
||||
} catch {
|
||||
Write-IcingaConsoleError -Message 'Failed to stop service "{0}". Error: {1}' -Objects $Service, $_.Exception.Message;
|
||||
}
|
||||
} -Args $Service;
|
||||
} else {
|
||||
Write-IcingaConsoleWarning -Message 'The service "{0}" is not installed' -Objects $Service;
|
||||
if ($Global:Icinga.Protected.ServiceRestartLock -And $Force -eq $FALSE) {
|
||||
return;
|
||||
}
|
||||
|
||||
Optimize-IcingaForWindowsMemory;
|
||||
$Result = Invoke-IcingaWindowsScheduledTask -JobType 'StopWindowsService' -ObjectName $Service;
|
||||
|
||||
if ($Result.Success -eq $FALSE) {
|
||||
Write-IcingaConsoleError $Result.ErrMsg;
|
||||
} else {
|
||||
Write-IcingaConsoleNotice $Result.Message;
|
||||
}
|
||||
|
||||
if ($Service -eq 'icinga2') {
|
||||
$Global:Icinga.Protected.IcingaServiceState = $Result.Status;
|
||||
} elseif ($Service -eq 'icingapowershell') {
|
||||
$Global:Icinga.Protected.IfWServiceState = $Result.Status;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,13 +18,6 @@ function Get-IcingaAgentInstallation()
|
|||
}
|
||||
}
|
||||
|
||||
$IcingaService = Get-IcingaServices -Service 'icinga2';
|
||||
$ServiceUser = 'NT AUTHORITY\NetworkService';
|
||||
|
||||
if ($null -ne $IcingaService) {
|
||||
$ServiceUser = $IcingaService.icinga2.configuration.ServiceUser;
|
||||
}
|
||||
|
||||
if ($null -eq $IcingaData) {
|
||||
return @{
|
||||
'Installed' = $FALSE;
|
||||
|
|
@ -33,7 +26,7 @@ function Get-IcingaAgentInstallation()
|
|||
'Architecture' = $architecture;
|
||||
'Uninstaller' = '';
|
||||
'InstallDate' = '';
|
||||
'User' = $ServiceUser;
|
||||
'User' = (Get-IcingaServiceUser);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -44,6 +37,6 @@ function Get-IcingaAgentInstallation()
|
|||
'Architecture' = $architecture;
|
||||
'Uninstaller' = $IcingaData.UninstallString.Replace("MsiExec.exe ", "");
|
||||
'InstallDate' = $IcingaData.InstallDate;
|
||||
'User' = $ServiceUser;
|
||||
'User' = (Get-IcingaServiceUser);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,31 @@
|
|||
function Get-IcingaServiceUser()
|
||||
{
|
||||
$Services = Get-IcingaServices -Service 'icinga2';
|
||||
if ($null -eq $Services) {
|
||||
$Services = Get-IcingaServices -Service 'icingapowershell';
|
||||
if ($null -eq $Services) {
|
||||
return $null;
|
||||
if ([string]::IsNullOrEmpty($Global:Icinga.Protected.IcingaServiceUser) -eq $FALSE) {
|
||||
return $Global:Icinga.Protected.IcingaServiceUser;
|
||||
}
|
||||
|
||||
$Services = Get-IcingaWindowsServiceStatus -Service 'icinga2';
|
||||
if ($Services.Present -eq $FALSE) {
|
||||
$Services = Get-IcingaWindowsServiceStatus -Service 'icingapowershell';
|
||||
if ($Services.Present -eq $FALSE) {
|
||||
return 'NT Authority\NetworkService';
|
||||
}
|
||||
}
|
||||
|
||||
$Services = $Services.GetEnumerator() | Select-Object -First 1;
|
||||
$ServiceUser = ($Services.Value.configuration.ServiceUser).Replace('.\', '');
|
||||
$ServiceUser = (Get-IcingaWindowsInformation Win32_Service |
|
||||
ForEach-Object {
|
||||
if ($_.Name -Like $Services.Name) {
|
||||
return $_;
|
||||
}
|
||||
} | Select-Object StartName).StartName;
|
||||
|
||||
$ServiceUser = $ServiceUser.Replace('.\', '');
|
||||
|
||||
if ($ServiceUser -eq 'LocalSystem') {
|
||||
$ServiceUser = 'NT Authority\SYSTEM';
|
||||
}
|
||||
|
||||
$Global:Icinga.Protected.IcingaServiceUser = $ServiceUser;
|
||||
|
||||
return $ServiceUser;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,18 +73,7 @@ function Install-IcingaAgent()
|
|||
}
|
||||
}
|
||||
|
||||
$InstallProcess = & powershell.exe -Command {
|
||||
Use-Icinga -Minimal;
|
||||
|
||||
$IcingaInstaller = $args[0];
|
||||
$InstallTarget = $args[1];
|
||||
$InstallProcess = Start-IcingaProcess -Executable 'MsiExec.exe' -Arguments ([string]::Format('/quiet /norestart /i "{0}" {1}', $IcingaInstaller.InstallerPath, $InstallTarget)) -FlushNewLines;
|
||||
|
||||
Start-Sleep -Seconds 2;
|
||||
Optimize-IcingaForWindowsMemory;
|
||||
|
||||
return $InstallProcess;
|
||||
} -Args $IcingaInstaller, $InstallTarget;
|
||||
$InstallProcess = Start-IcingaProcess -Executable 'MsiExec.exe' -Arguments ([string]::Format('/quiet /i "{0}" {1}', $IcingaInstaller.InstallerPath, $InstallTarget)) -FlushNewLines;
|
||||
|
||||
if ($InstallProcess.ExitCode -ne 0) {
|
||||
Write-IcingaConsoleError -Message 'Failed to install Icinga 2 Agent: {0}{1}' -Objects $InstallProcess.Message, $InstallProcess.Error;
|
||||
|
|
|
|||
|
|
@ -22,17 +22,7 @@ function Uninstall-IcingaAgent()
|
|||
|
||||
Stop-IcingaService -Service 'icinga2';
|
||||
|
||||
$Uninstaller = & powershell.exe -Command {
|
||||
Use-Icinga -Minimal;
|
||||
|
||||
$IcingaData = $args[0];
|
||||
$Uninstaller = Start-IcingaProcess -Executable 'MsiExec.exe' -Arguments ([string]::Format('{0} /q /norestart', $IcingaData.Uninstaller)) -FlushNewLine;
|
||||
|
||||
Start-Sleep -Seconds 2;
|
||||
Optimize-IcingaForWindowsMemory;
|
||||
|
||||
return $Uninstaller;
|
||||
} -Args $IcingaData;
|
||||
$Uninstaller = Invoke-IcingaWindowsScheduledTask -JobType UninstallAgent -FilePath $IcingaData.Uninstaller;
|
||||
|
||||
if ($Uninstaller.ExitCode -ne 0) {
|
||||
Write-IcingaConsoleError ([string]::Format('Failed to remove Icinga Agent: {0}{1}', $Uninstaller.Message, $Uninstaller.Error));
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ function Clear-IcingaAgentApiDirectory()
|
|||
[switch]$Force = $FALSE
|
||||
);
|
||||
|
||||
$IcingaService = (Get-IcingaServices -Service icinga2).icinga2;
|
||||
$IcingaService = Get-IcingaWindowsServiceStatus -Service 'icinga2';
|
||||
$ApiDirectory = (Join-Path -Path $Env:ProgramData -ChildPath 'icinga2\var\lib\icinga2\api\');
|
||||
|
||||
if ((Test-Path $ApiDirectory) -eq $FALSE) {
|
||||
|
|
@ -36,12 +36,12 @@ function Clear-IcingaAgentApiDirectory()
|
|||
return;
|
||||
}
|
||||
|
||||
if ($IcingaService.configuration.Status.raw -eq 4 -And $Force -eq $FALSE) {
|
||||
if ($IcingaService.Status -eq 'Running' -And $Force -eq $FALSE) {
|
||||
Write-IcingaConsoleError 'The API directory can not be deleted while the Icinga Agent is running. Use the "-Force" argument to stop the service, flush the directory and restart the service again.';
|
||||
return;
|
||||
}
|
||||
|
||||
if ($IcingaService.configuration.Status.raw -eq 4) {
|
||||
if ($IcingaService.Status -eq 'Running') {
|
||||
Stop-IcingaService icinga2;
|
||||
Start-Sleep -Seconds 1;
|
||||
}
|
||||
|
|
@ -50,7 +50,7 @@ function Clear-IcingaAgentApiDirectory()
|
|||
Remove-ItemSecure -Path (Join-Path -Path $ApiDirectory -ChildPath '*') -Recurse -Force | Out-Null;
|
||||
Start-Sleep -Seconds 1;
|
||||
|
||||
if ($IcingaService.configuration.Status.raw -eq 4) {
|
||||
if ($IcingaService.Status -eq 'Running') {
|
||||
Start-IcingaService icinga2;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -754,7 +754,7 @@ function Start-IcingaAgentInstallWizard()
|
|||
if ($InstallFrameworkService) {
|
||||
Restart-IcingaForWindows;
|
||||
}
|
||||
Restart-IcingaService 'icinga2';
|
||||
Restart-IcingaService 'icinga2' -Force;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ function Repair-IcingaService()
|
|||
[string]$RootFolder = ''
|
||||
);
|
||||
|
||||
if ($null -ne (Get-Service 'icinga2' -ErrorAction SilentlyContinue)) {
|
||||
if ((Get-IcingaWindowsServiceStatus -Service 'icinga2').Present) {
|
||||
Write-IcingaConsoleNotice -Message 'The Icinga Agent service is already installed. If you received the error "The specified service has been marked for deletion", please have a look at https://icinga.com/docs/icinga-for-windows/latest/doc/knowledgebase/IWKB000011/'
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ function Set-IcingaServiceUser()
|
|||
return $FALSE;
|
||||
}
|
||||
|
||||
if ($null -eq (Get-Service $Service -ErrorAction SilentlyContinue)) {
|
||||
if ((Get-IcingaWindowsServiceStatus -Service $Service).Present -eq $FALSE) {
|
||||
return $FALSE;
|
||||
}
|
||||
|
||||
|
|
@ -40,6 +40,12 @@ function Set-IcingaServiceUser()
|
|||
Set-IcingaUserPermissions;
|
||||
}
|
||||
|
||||
if ($Service -eq 'icinga2') {
|
||||
$Global:Icinga.Protected.IcingaServiceUser = $User;
|
||||
} elseif ($Service -eq 'icingapowershell') {
|
||||
$Global:Icinga.Protected.IfWServiceUser = $User;
|
||||
}
|
||||
|
||||
Write-IcingaConsoleNotice 'Service User "{0}" for service "{1}" successfully updated' -Objects $User, $Service;
|
||||
return $TRUE;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
function Test-IcingaAgent()
|
||||
{
|
||||
$IcingaAgentData = Get-IcingaAgentInstallation;
|
||||
$AgentServicePresent = Get-Service 'icinga2' -ErrorAction SilentlyContinue;
|
||||
if ($IcingaAgentData.Installed -And $null -ne $AgentServicePresent) {
|
||||
$AgentServicePresent = Get-IcingaWindowsServiceStatus -Service 'icinga2';
|
||||
if ($IcingaAgentData.Installed -And $AgentServicePresent.Present) {
|
||||
Write-IcingaTestOutput -Severity 'Passed' -Message 'Icinga Agent service is installed';
|
||||
} elseif ($IcingaAgentData.Installed -And $null -eq $AgentServicePresent) {
|
||||
} elseif ($IcingaAgentData.Installed -And $AgentServicePresent.Present -eq $FALSE) {
|
||||
Write-IcingaTestOutput -Severity 'Failed' -Message 'Icinga Agent service is not installed';
|
||||
} elseif ($IcingaAgentData.Installed -eq $FALSE -And $null -ne $AgentServicePresent) {
|
||||
} elseif ($IcingaAgentData.Installed -eq $FALSE -And $AgentServicePresent.Present) {
|
||||
Write-IcingaTestOutput -Severity 'Failed' -Message 'Icinga Agent service is still present, while Icinga Agent itself is not installed.';
|
||||
} elseif ($IcingaAgentData.Installed -eq $FALSE -And $null -eq $AgentServicePresent) {
|
||||
} elseif ($IcingaAgentData.Installed -eq $FALSE -And $AgentServicePresent.Present -eq $FALSE) {
|
||||
Write-IcingaTestOutput -Severity 'Passed' -Message 'Icinga Agent is not installed and service is not present.';
|
||||
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ function Install-Icinga()
|
|||
# Always ensure we use the proper TLS Version
|
||||
Set-IcingaTLSVersion;
|
||||
|
||||
$Global:Icinga.Protected.ServiceRestartLock = $TRUE;
|
||||
|
||||
# Ignore SSL validation in case we set the flag
|
||||
if ($NoSSLValidation) {
|
||||
Enable-IcingaUntrustedCertificateValidation;
|
||||
|
|
@ -68,6 +70,7 @@ function Install-Icinga()
|
|||
$JsonInstallCmd = ConvertFrom-Json -InputObject $InstallCommand -ErrorAction Stop;
|
||||
} catch {
|
||||
Write-IcingaConsoleError 'Failed to deserialize the provided JSON from file or command: {0}' -Objects $_.Exception.Message;
|
||||
Clear-IcingaInternalServiceInformation;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -81,6 +84,7 @@ function Install-Icinga()
|
|||
$Success = Invoke-IcingaForWindowsManagementConsoleCustomConfig -IcingaConfiguration $IcingaConfiguration;
|
||||
|
||||
if ($Success -eq $FALSE) {
|
||||
Clear-IcingaInternalServiceInformation;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -101,6 +105,7 @@ function Install-Icinga()
|
|||
$Success = Invoke-IcingaForWindowsManagementConsoleCustomConfig -IcingaConfiguration $IcingaConfiguration;
|
||||
|
||||
if ($Success -eq $FALSE) {
|
||||
Clear-IcingaInternalServiceInformation;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -111,7 +116,7 @@ function Install-Icinga()
|
|||
# Set our "old" swap live again. By doing so, we can still continue our old
|
||||
# configuration
|
||||
Set-IcingaPowerShellConfig -Path 'Framework.Config.Swap' -Value $OldConfigSwap;
|
||||
|
||||
Clear-IcingaInternalServiceInformation;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -186,6 +191,8 @@ function Install-Icinga()
|
|||
}
|
||||
}
|
||||
|
||||
Clear-IcingaInternalServiceInformation;
|
||||
|
||||
if ($null -ne (Get-Command -Name 'Set-IcingaForWindowsManagementConsoleClosing' -ErrorAction SilentlyContinue)) {
|
||||
Set-IcingaForWindowsManagementConsoleClosing -Completed;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,6 @@ function Start-IcingaForWindowsInstallation()
|
|||
$PluginPackageRelease = $FALSE;
|
||||
$PluginPackageSnapshot = $FALSE;
|
||||
$ForceCertificateGen = $FALSE;
|
||||
[bool]$InstallJEA = $FALSE;
|
||||
[bool]$InstallRESTApi = $FALSE;
|
||||
|
||||
if ([string]::IsNullOrEmpty($IcingaStableRepo) -eq $FALSE) {
|
||||
|
|
@ -323,6 +322,21 @@ function Start-IcingaForWindowsInstallation()
|
|||
$global:Icinga.InstallWizard.Config = @{ };
|
||||
Set-IcingaPowerShellConfig -Path 'Framework.Installed' -Value $TRUE;
|
||||
|
||||
# Always install the JEA profile at the end
|
||||
switch ($InstallJEAProfile) {
|
||||
'0' {
|
||||
Invoke-IcingaWindowsScheduledTask -JobType InstallJEA -Timeout 600 | Out-Null;
|
||||
break;
|
||||
};
|
||||
'1' {
|
||||
Install-IcingaSecurity -RunAsTask;
|
||||
break;
|
||||
};
|
||||
'2' {
|
||||
# Do not install JEA profile
|
||||
};
|
||||
}
|
||||
|
||||
if ($Automated -eq $FALSE) {
|
||||
Write-IcingaConsoleNotice 'Icinga for Windows is installed. Returning to main menu in 5 seconds'
|
||||
Start-Sleep -Seconds 5;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ function Show-IcingaForWindowsMenuManage()
|
|||
'Caption' = 'Services';
|
||||
'Command' = 'Show-IcingaForWindowsMenuManageIcingaForWindowsServices';
|
||||
'Help' = 'Allows you to manage the Icinga Agent and Icinga for Windows service';
|
||||
'Disabled' = (-Not $AgentInstalled -And -Not ([bool](Get-Service 'icingapowershell' -ErrorAction SilentlyContinue)));
|
||||
'Disabled' = (-Not $AgentInstalled -And -Not (Get-IcingaWindowsServiceStatus -Service 'icingapowershell').Present);
|
||||
'AdminMenu' = $TRUE;
|
||||
},
|
||||
@{
|
||||
|
|
@ -28,7 +28,7 @@ function Show-IcingaForWindowsMenuManage()
|
|||
'Caption' = 'Background Daemons';
|
||||
'Command' = 'Show-IcingaForWindowsManagementConsoleManageBackgroundDaemons';
|
||||
'Help' = 'Allows you to manage Icinga for Windows background daemons';
|
||||
'Disabled' = ($null -eq (Get-Service 'icingapowershell' -ErrorAction SilentlyContinue));
|
||||
'Disabled' = (-Not (Get-IcingaWindowsServiceStatus -Service 'icingapowershell').Present);
|
||||
'DisabledReason' = 'Icinga for Windows service is not installed';
|
||||
},
|
||||
@{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ function Show-IcingaForWindowsMenuRemoveComponents()
|
|||
{
|
||||
[array]$UninstallFeatures = @();
|
||||
$AgentInstalled = (Get-IcingaAgentInstallation).Installed;
|
||||
$PowerShellServiceInstalled = Get-Service -Name 'icingapowershell' -ErrorAction SilentlyContinue;
|
||||
$PowerShellServiceInstalled = Get-IcingaWindowsServiceStatus -Service 'icingapowershell';
|
||||
$IcingaWindowsServiceData = Get-IcingaForWindowsServiceData;
|
||||
$ModuleList = Get-Module 'icinga-powershell-*' -ListAvailable;
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ function Show-IcingaForWindowsMenuRemoveComponents()
|
|||
'Caption' = 'Uninstall Icinga for Windows Service';
|
||||
'Command' = 'Show-IcingaForWindowsMenuRemoveComponents';
|
||||
'Help' = 'This will remove the icingapowershell service for Icinga for Windows if installed'
|
||||
'Disabled' = ($null -eq $PowerShellServiceInstalled);
|
||||
'Disabled' = (-Not $PowerShellServiceInstalled.Present);
|
||||
'Action' = @{
|
||||
'Command' = 'Show-IcingaWindowsManagementConsoleYesNoDialog';
|
||||
'Arguments' = @{
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
function Show-IcingaForWindowsMenuManageIcingaForWindowsServices()
|
||||
{
|
||||
$IcingaAgentService = Get-Service 'icinga2' -ErrorAction SilentlyContinue;
|
||||
$IcingaAgentService = Get-IcingaWindowsServiceStatus -Service 'icinga2';
|
||||
$IcingaAgentStatus = 'Not Installed';
|
||||
$IcingaForWindowsService = Get-Service 'icingapowershell' -ErrorAction SilentlyContinue;
|
||||
$IcingaForWindowsService = Get-IcingaWindowsServiceStatus -Service 'icingapowershell';
|
||||
$IcingaForWindowsStatus = 'Not Installed';
|
||||
|
||||
if ($null -ne $IcingaAgentService) {
|
||||
if ($IcingaAgentService.Present) {
|
||||
$IcingaAgentStatus = $IcingaAgentService.Status;
|
||||
}
|
||||
|
||||
if ($null -ne $IcingaForWindowsService) {
|
||||
if ($IcingaForWindowsService.Present) {
|
||||
$IcingaForWindowsStatus = $IcingaForWindowsService.Status;
|
||||
}
|
||||
|
||||
|
|
@ -20,43 +20,43 @@ function Show-IcingaForWindowsMenuManageIcingaForWindowsServices()
|
|||
'Caption' = 'Start Icinga Agent Service';
|
||||
'Command' = 'Show-IcingaForWindowsMenuManageIcingaForWindowsServices';
|
||||
'Help' = 'Allows you to start the Icinga Agent if the service is not running';
|
||||
'Disabled' = ($null -eq $IcingaAgentService -Or $IcingaAgentStatus -eq 'Running');
|
||||
'Disabled' = (-Not $IcingaAgentService.Present -Or $IcingaAgentStatus -eq 'Running');
|
||||
'DisabledReason' = 'The Icinga Agent service is either not installed or the service is already running';
|
||||
'AdminMenu' = $TRUE;
|
||||
'Action' = @{
|
||||
'Command' = 'Start-IcingaService';
|
||||
'Arguments' = @{ '-Service' = 'icinga2'; };
|
||||
'Arguments' = @{ '-Service' = 'icinga2'; '-Force' = $TRUE; };
|
||||
}
|
||||
},
|
||||
@{
|
||||
'Caption' = 'Stop Icinga Agent Service';
|
||||
'Command' = 'Show-IcingaForWindowsMenuManageIcingaForWindowsServices';
|
||||
'Help' = 'Allows you to stop the Icinga Agent if the service is not running';
|
||||
'Disabled' = ($null -eq $IcingaAgentService -Or $IcingaAgentStatus -ne 'Running');
|
||||
'Disabled' = (-Not $IcingaAgentService.Present -Or $IcingaAgentStatus -ne 'Running');
|
||||
'DisabledReason' = 'The Icinga Agent service is either not installed or the service is not running';
|
||||
'AdminMenu' = $TRUE;
|
||||
'Action' = @{
|
||||
'Command' = 'Stop-IcingaService';
|
||||
'Arguments' = @{ '-Service' = 'icinga2'; };
|
||||
'Arguments' = @{ '-Service' = 'icinga2'; '-Force' = $TRUE; };
|
||||
}
|
||||
},
|
||||
@{
|
||||
'Caption' = 'Restart Icinga Agent Service';
|
||||
'Command' = 'Show-IcingaForWindowsMenuManageIcingaForWindowsServices';
|
||||
'Help' = 'Allows you to restart the Icinga Agent if the service is installed';
|
||||
'Disabled' = ($null -eq $IcingaAgentService);
|
||||
'Disabled' = (-Not $IcingaAgentService.Present);
|
||||
'DisabledReason' = 'The Icinga Agent service is not installed';
|
||||
'AdminMenu' = $TRUE;
|
||||
'Action' = @{
|
||||
'Command' = 'Restart-IcingaService';
|
||||
'Arguments' = @{ '-Service' = 'icinga2'; };
|
||||
'Arguments' = @{ '-Service' = 'icinga2'; '-Force' = $TRUE; };
|
||||
}
|
||||
},
|
||||
@{
|
||||
'Caption' = 'Repair Icinga Agent Service';
|
||||
'Command' = 'Show-IcingaForWindowsMenuManageIcingaForWindowsServices';
|
||||
'Help' = 'Allows to repair the Icinga Agent service in case it was removed or broke during installation/upgrade';
|
||||
'Disabled' = ($null -ne $IcingaAgentService);
|
||||
'Disabled' = ($IcingaAgentService.Present);
|
||||
'DisabledReason' = 'The Icinga Agent service is already present';
|
||||
'AdminMenu' = $TRUE;
|
||||
'Action' = @{
|
||||
|
|
@ -67,19 +67,19 @@ function Show-IcingaForWindowsMenuManageIcingaForWindowsServices()
|
|||
'Caption' = 'Start Icinga for Windows Service';
|
||||
'Command' = 'Show-IcingaForWindowsMenuManageIcingaForWindowsServices';
|
||||
'Help' = 'Allows you to start the Icinga for Windows Service if the service is not running';
|
||||
'Disabled' = ($null -eq $IcingaForWindowsService -Or $IcingaForWindowsStatus -eq 'Running');
|
||||
'Disabled' = (-Not $IcingaForWindowsService.Present -Or $IcingaForWindowsStatus -eq 'Running');
|
||||
'DisabledReason' = 'The Icinga for Windows service is either not installed or already running';
|
||||
'AdminMenu' = $TRUE;
|
||||
'Action' = @{
|
||||
'Command' = 'Start-IcingaService';
|
||||
'Arguments' = @{ '-Service' = 'icingapowershell'; };
|
||||
'Arguments' = @{ '-Service' = 'icingapowershell'; '-Force' = $TRUE; };
|
||||
}
|
||||
},
|
||||
@{
|
||||
'Caption' = 'Stop Icinga for Windows Service';
|
||||
'Command' = 'Show-IcingaForWindowsMenuManageIcingaForWindowsServices';
|
||||
'Help' = 'Allows you to stop the Icinga for Windows Service if the service is not running';
|
||||
'Disabled' = ($null -eq $IcingaForWindowsService -Or $IcingaForWindowsStatus -ne 'Running');
|
||||
'Disabled' = (-Not $IcingaForWindowsService.Present -Or $IcingaForWindowsStatus -ne 'Running');
|
||||
'DisabledReason' = 'The Icinga for Windows service is either not installed or not running';
|
||||
'AdminMenu' = $TRUE;
|
||||
'Action' = @{
|
||||
|
|
@ -90,7 +90,7 @@ function Show-IcingaForWindowsMenuManageIcingaForWindowsServices()
|
|||
'Caption' = 'Restart Icinga for Windows Service';
|
||||
'Command' = 'Show-IcingaForWindowsMenuManageIcingaForWindowsServices';
|
||||
'Help' = 'Allows you to restart the Icinga for Windows Service if the service is installed';
|
||||
'Disabled' = ($null -eq $IcingaForWindowsService);
|
||||
'Disabled' = (-Not $IcingaForWindowsService.Present);
|
||||
'DisabledReason' = 'The Icinga for Windows service is not installed';
|
||||
'AdminMenu' = $TRUE;
|
||||
'Action' = @{
|
||||
|
|
@ -101,7 +101,7 @@ function Show-IcingaForWindowsMenuManageIcingaForWindowsServices()
|
|||
'Caption' = 'Enable recovery settings for services';
|
||||
'Command' = 'Show-IcingaForWindowsMenuManageIcingaForWindowsServices';
|
||||
'Help' = 'Enables automatic service recovery for the Icinga Agent and Icinga for Windows service, in case the server terminates itself because of errors';
|
||||
'Disabled' = ($null -eq $IcingaForWindowsService -And $null -eq $IcingaAgentService);
|
||||
'Disabled' = (-Not $IcingaForWindowsService.Present -And -Not $IcingaAgentService.Present);
|
||||
'DisabledReason' = 'Neither the Icinga Agent nor the Icinga for Windows service are installed';
|
||||
'AdminMenu' = $TRUE;
|
||||
'Action' = @{
|
||||
|
|
@ -112,7 +112,7 @@ function Show-IcingaForWindowsMenuManageIcingaForWindowsServices()
|
|||
'Caption' = 'Disable recovery settings for services';
|
||||
'Command' = 'Show-IcingaForWindowsMenuManageIcingaForWindowsServices';
|
||||
'Help' = 'Disables automatic service recovery for the Icinga Agent and Icinga for Windows service, in case the server terminates itself because of errors';
|
||||
'Disabled' = ($null -eq $IcingaForWindowsService -And $null -eq $IcingaAgentService);
|
||||
'Disabled' = (-Not $IcingaForWindowsService.Present -And -Not $IcingaAgentService.Present);
|
||||
'DisabledReason' = 'Neither the Icinga Agent nor the Icinga for Windows service are installed';
|
||||
'AdminMenu' = $TRUE;
|
||||
'Action' = @{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
function Show-IcingaForWindowsMenuManageTroubleshooting()
|
||||
{
|
||||
$IcingaAgentService = Get-Service 'icinga2' -ErrorAction SilentlyContinue;
|
||||
$IcingaAgentService = Get-IcingaWindowsServiceStatus -Service 'icinga2';
|
||||
|
||||
Show-IcingaForWindowsInstallerMenu `
|
||||
-Header 'Troubleshooting options for problems:' `
|
||||
|
|
@ -45,7 +45,7 @@ function Show-IcingaForWindowsMenuManageTroubleshooting()
|
|||
'Caption' = 'Repair Icinga Agent service';
|
||||
'Command' = 'Show-IcingaForWindowsMenuManageTroubleshooting';
|
||||
'Help' = 'Allows to repair the Icinga Agent service in case it was removed or broke during installation/upgrade';
|
||||
'Disabled' = ($null -ne $IcingaAgentService);
|
||||
'Disabled' = (-Not $IcingaAgentService.Present);
|
||||
'DisabledReason' = 'The Icinga Agent service is already present';
|
||||
'AdminMenu' = $TRUE;
|
||||
'Action' = @{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
function Install-IcingaJEAProfile()
|
||||
{
|
||||
param (
|
||||
[string]$IcingaUser = ((Get-IcingaServices).icinga2.configuration.ServiceUser),
|
||||
[string]$IcingaUser = (Get-IcingaServiceUser),
|
||||
[switch]$ConstrainedLanguage = $FALSE,
|
||||
[switch]$TestEnv = $FALSE,
|
||||
[switch]$RebuildFramework = $FALSE,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
function Register-IcingaJEAProfile()
|
||||
{
|
||||
param (
|
||||
[string]$IcingaUser = ((Get-IcingaServices).icinga2.configuration.ServiceUser),
|
||||
[string]$IcingaUser = (Get-IcingaServiceUser),
|
||||
[switch]$ConstrainedLanguage = $FALSE,
|
||||
[switch]$TestEnv = $FALSE
|
||||
);
|
||||
|
|
|
|||
|
|
@ -152,8 +152,8 @@ function Install-IcingaComponent()
|
|||
# These update steps only apply for the framework
|
||||
if ($Name.ToLower() -eq 'framework') {
|
||||
Remove-IcingaFrameworkDependencyFile;
|
||||
$ServiceStatus = (Get-Service 'icingapowershell' -ErrorAction SilentlyContinue).Status;
|
||||
$AgentStatus = (Get-Service 'icinga2' -ErrorAction SilentlyContinue).Status;
|
||||
$ServiceStatus = (Get-IcingaWindowsServiceStatus -Service 'icingapowershell').Status;
|
||||
$AgentStatus = (Get-IcingaWindowsServiceStatus -Service 'icinga2').Status;
|
||||
|
||||
if ($ServiceStatus -eq 'Running') {
|
||||
Write-IcingaConsoleNotice 'Stopping Icinga for Windows service';
|
||||
|
|
@ -351,12 +351,7 @@ function Install-IcingaComponent()
|
|||
}
|
||||
}
|
||||
|
||||
$MSIData = & powershell.exe -Command {
|
||||
Use-Icinga -Minimal;
|
||||
|
||||
$DownloadDestination = $args[0];
|
||||
return (Read-IcingaMSIMetadata -File $DownloadDestination);
|
||||
} -Args $DownloadDestination;
|
||||
$MSIData = Invoke-IcingaWindowsScheduledTask -JobType ReadMSIPackage -FilePath $DownloadDestination;
|
||||
|
||||
if ($InstalledVersion.Full -eq $MSIData.ProductVersion -And $Force -eq $FALSE) {
|
||||
Write-IcingaConsoleWarning 'The package "agent" with version "{0}" is already installed. Use "-Force" to re-install the component' -Objects $InstalledVersion.Full;
|
||||
|
|
@ -373,18 +368,7 @@ function Install-IcingaComponent()
|
|||
}
|
||||
}
|
||||
|
||||
$InstallProcess = & powershell.exe -Command {
|
||||
Use-Icinga -Minimal;
|
||||
|
||||
$DownloadDestination = $args[0];
|
||||
$InstallTarget = $args[1];
|
||||
$InstallProcess = Start-IcingaProcess -Executable 'MsiExec.exe' -Arguments ([string]::Format('/quiet /norestart /i "{0}" {1}', $DownloadDestination, $InstallTarget)) -FlushNewLines;
|
||||
|
||||
Start-Sleep -Seconds 2;
|
||||
Optimize-IcingaForWindowsMemory;
|
||||
|
||||
return $InstallProcess;
|
||||
} -Args $DownloadDestination, $InstallTarget;
|
||||
$InstallProcess = Start-IcingaProcess -Executable 'MsiExec.exe' -Arguments ([string]::Format('/quiet /i "{0}" {1}', $DownloadDestination, $InstallTarget)) -FlushNewLines;
|
||||
|
||||
if ($InstallProcess.ExitCode -ne 0) {
|
||||
Write-IcingaConsoleError -Message 'Failed to install component "agent": {0}{1}' -Objects $InstallProcess.Message, $InstallProcess.Error;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
function Disable-IcingaServiceRecovery()
|
||||
{
|
||||
if ($null -ne (Get-Service 'icinga2' -ErrorAction SilentlyContinue)) {
|
||||
if ((Get-IcingaWindowsServiceStatus -Service 'icinga2').Present) {
|
||||
$ServiceStatus = Start-IcingaProcess -Executable 'sc.exe' -Arguments 'failure icinga2 reset=0 actions=none/0/none/0/none/0';
|
||||
|
||||
if ($ServiceStatus.ExitCode -ne 0) {
|
||||
|
|
@ -10,7 +10,7 @@ function Disable-IcingaServiceRecovery()
|
|||
}
|
||||
}
|
||||
|
||||
if ($null -ne (Get-Service 'icingapowershell' -ErrorAction SilentlyContinue)) {
|
||||
if ((Get-IcingaWindowsServiceStatus -Service 'icingapowershell').Present) {
|
||||
$ServiceStatus = Start-IcingaProcess -Executable 'sc.exe' -Arguments 'failure icingapowershell reset=0 actions=none/0/none/0/none/0';
|
||||
|
||||
if ($ServiceStatus.ExitCode -ne 0) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
function Enable-IcingaServiceRecovery()
|
||||
{
|
||||
if ($null -ne (Get-Service 'icinga2' -ErrorAction SilentlyContinue)) {
|
||||
if ((Get-IcingaWindowsServiceStatus -Service 'icinga2').Present) {
|
||||
$ServiceStatus = Start-IcingaProcess -Executable 'sc.exe' -Arguments 'failure icinga2 reset=0 actions=restart/0/restart/0/restart/0';
|
||||
|
||||
if ($ServiceStatus.ExitCode -ne 0) {
|
||||
|
|
@ -10,7 +10,7 @@ function Enable-IcingaServiceRecovery()
|
|||
}
|
||||
}
|
||||
|
||||
if ($null -ne (Get-Service 'icingapowershell' -ErrorAction SilentlyContinue)) {
|
||||
if ((Get-IcingaWindowsServiceStatus -Service 'icingapowershell').Present) {
|
||||
$ServiceStatus = Start-IcingaProcess -Executable 'sc.exe' -Arguments 'failure icingapowershell reset=0 actions=restart/0/restart/0/restart/0';
|
||||
|
||||
if ($ServiceStatus.ExitCode -ne 0) {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ function Install-IcingaSecurity()
|
|||
[string]$IcingaUser = 'icinga',
|
||||
[switch]$RebuildFramework = $FALSE,
|
||||
[switch]$AllowScriptBlocks = $FALSE,
|
||||
[switch]$ConstrainedLanguage = $FALSE
|
||||
[switch]$ConstrainedLanguage = $FALSE,
|
||||
[switch]$RunAsTask = $FALSE
|
||||
);
|
||||
|
||||
if ($PSVersionTable.PSVersion -lt (New-IcingaVersionObject -Version 5, 0)) {
|
||||
|
|
@ -27,7 +28,12 @@ function Install-IcingaSecurity()
|
|||
}
|
||||
|
||||
Install-IcingaServiceUser -IcingaUser $IcingaUser;
|
||||
Install-IcingaJEAProfile -IcingaUser $IcingaUser -RebuildFramework:$RebuildFramework -AllowScriptBlocks:$AllowScriptBlocks -ConstrainedLanguage:$ConstrainedLanguage;
|
||||
|
||||
if ($RunAsTask) {
|
||||
Invoke-IcingaWindowsScheduledTask -JobType InstallJEA -Timeout 600 | Out-Null;
|
||||
} else {
|
||||
Install-IcingaJEAProfile -IcingaUser $IcingaUser -RebuildFramework:$RebuildFramework -AllowScriptBlocks:$AllowScriptBlocks -ConstrainedLanguage:$ConstrainedLanguage;
|
||||
}
|
||||
|
||||
Restart-IcingaForWindows;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,22 @@
|
|||
function Restart-IcingaForWindows()
|
||||
{
|
||||
param (
|
||||
[switch]$Force = $FALSE
|
||||
);
|
||||
|
||||
if ($Global:Icinga.Protected.ServiceRestartLock -And $Force -eq $FALSE) {
|
||||
return;
|
||||
}
|
||||
|
||||
[string]$JeaPid = Get-IcingaJEAServicePid;
|
||||
|
||||
Stop-IcingaService -Service 'icingapowershell';
|
||||
Stop-IcingaService -Service 'icingapowershell' -Force:$Force;
|
||||
|
||||
if ((Test-IcingaJEAServiceRunning -JeaPid $JeaPid)) {
|
||||
Stop-IcingaJEAProcess -JeaPid $JeaPid;
|
||||
}
|
||||
|
||||
Restart-IcingaService -Service 'icingapowershell';
|
||||
Restart-IcingaService -Service 'icingapowershell' -Force:$Force;
|
||||
}
|
||||
|
||||
Set-Alias -Name 'Restart-IcingaWindowsService' -Value 'Restart-IcingaForWindows';
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ function Uninstall-IcingaServiceUser()
|
|||
|
||||
Write-IcingaConsoleNotice 'Uninstalling user "{0}"' -Objects $IcingaUser;
|
||||
|
||||
Stop-IcingaService 'icinga2';
|
||||
Stop-IcingaWindowsService;
|
||||
Stop-IcingaService 'icinga2' -Force;
|
||||
Stop-IcingaWindowsService -Force;
|
||||
|
||||
Set-IcingaPowerShellConfig -Path 'Framework.Icinga.ServiceUser' -Value '';
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue