mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Merge pull request #521 from Icinga:feature/adds_service_recovery
Feature: Adds support for service recovery Adds support to set service recovery for the Icinga Agent and Icinga for Windows service, to restart them in case of a crash or error
This commit is contained in:
commit
42320b55b3
7 changed files with 123 additions and 2 deletions
|
|
@ -7,12 +7,20 @@ documentation before upgrading to a new release.
|
|||
|
||||
Released closed milestones can be found on [GitHub](https://github.com/Icinga/icinga-powershell-framework/milestones?state=closed).
|
||||
|
||||
## 1.10.0 (2022-08-16)
|
||||
|
||||
[Issue and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/23?closed=1)
|
||||
|
||||
### Enhancements
|
||||
|
||||
* [#40](https://github.com/Icinga/icinga-powershell-framework/issues/40) Adds support to set service recovery for the Icinga Agent and Icinga for Windows service, to restart them in case of a crash or error
|
||||
|
||||
## 1.9.1 (2022-05-13)
|
||||
|
||||
### Bugfixes
|
||||
|
||||
[Issue and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/24?closed=1)
|
||||
|
||||
### Bugfixes
|
||||
|
||||
* [#519](https://github.com/Icinga/icinga-powershell-framework/pull/519) Fixes missing loading of Icinga for Windows modules, which is required to ensure an Icinga for Windows environment is providing all commands and variables to a session, allowing other modules to access these information
|
||||
* [#520](https://github.com/Icinga/icinga-powershell-framework/pull/520) Adds missing `Import-IcingaPowerShellComponent` function while creating new components by using the developer tools
|
||||
|
||||
|
|
|
|||
|
|
@ -60,6 +60,9 @@ function Start-IcingaForWindowsInstallation()
|
|||
# Api Checks
|
||||
$InstallApiChecks = Get-IcingaForWindowsInstallerStepSelection -InstallerStep 'Show-IcingaForWindowsInstallerMenuSelectInstallApiChecks';
|
||||
|
||||
# Service Recovery
|
||||
$ServiceRecovery = Get-IcingaForWindowsInstallerStepSelection -InstallerStep 'Show-IcingaForWindowsInstallerMenuSelectServiceRecovery';
|
||||
|
||||
$Hostname = '';
|
||||
$GlobalZones = @();
|
||||
$IcingaParentAddresses = @();
|
||||
|
|
@ -284,6 +287,17 @@ function Start-IcingaForWindowsInstallation()
|
|||
};
|
||||
}
|
||||
|
||||
switch ($ServiceRecovery) {
|
||||
'0' {
|
||||
Disable-IcingaServiceRecovery;
|
||||
break;
|
||||
};
|
||||
'1' {
|
||||
Enable-IcingaServiceRecovery;
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
# Install Icinga for Windows certificate if both, JEA and REST is installed
|
||||
if ($InstallJEA -And $InstallRESTApi) {
|
||||
Install-IcingaForWindowsCertificate;
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ function Add-IcingaForWindowsInstallationAdvancedEntries()
|
|||
Show-IcingaForWindowsInstallerMenuSelectInstallJEAProfile -Automated -Advanced;
|
||||
Show-IcingaForWindowsInstallationMenuEnterIcingaCAServer -Automated -Advanced;
|
||||
Show-IcingaForWindowsInstallerMenuSelectInstallApiChecks -Automated -Advanced;
|
||||
Show-IcingaForWindowsInstallerMenuSelectServiceRecovery -Automated -Advanced;
|
||||
|
||||
Enable-IcingaFrameworkConsoleOutput;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
function Show-IcingaForWindowsInstallerMenuSelectServiceRecovery()
|
||||
{
|
||||
param (
|
||||
[array]$Value = @(),
|
||||
[string]$DefaultInput = '1',
|
||||
[switch]$JumpToSummary = $FALSE,
|
||||
[switch]$Automated = $FALSE,
|
||||
[switch]$Advanced = $FALSE
|
||||
);
|
||||
|
||||
Show-IcingaForWindowsInstallerMenu `
|
||||
-Header 'Please select if you want to enable or disable automatic service recovery' `
|
||||
-Entries @(
|
||||
@{
|
||||
'Caption' = 'Disable automatic service recovery';
|
||||
'Command' = 'Show-IcingaForWindowsInstallerConfigurationSummary';
|
||||
'Help' = 'Enables automatic service recovery for the Icinga Agent and Icinga for Windows service, in case the server terminates itself because of errors';
|
||||
},
|
||||
@{
|
||||
'Caption' = 'Enable automatic service recovery';
|
||||
'Command' = 'Show-IcingaForWindowsInstallerConfigurationSummary';
|
||||
'Help' = 'Disables automatic service recovery for the Icinga Agent and Icinga for Windows service, in case the server terminates itself because of errors';
|
||||
}
|
||||
) `
|
||||
-DefaultIndex $DefaultInput `
|
||||
-JumpToSummary:$FALSE `
|
||||
-ConfigElement `
|
||||
-Automated:$Automated `
|
||||
-Advanced:$Advanced;
|
||||
}
|
||||
|
||||
Set-Alias -Name 'IfW-ServiceRecovery' -Value 'Show-IcingaForWindowsInstallerMenuSelectServiceRecovery';
|
||||
|
|
@ -96,6 +96,28 @@ function Show-IcingaForWindowsMenuManageIcingaForWindowsServices()
|
|||
'Action' = @{
|
||||
'Command' = 'Restart-IcingaWindowsService';
|
||||
}
|
||||
},
|
||||
@{
|
||||
'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);
|
||||
'DisabledReason' = 'Neither the Icinga Agent nor the Icinga for Windows service are installed';
|
||||
'AdminMenu' = $TRUE;
|
||||
'Action' = @{
|
||||
'Command' = 'Enable-IcingaServiceRecovery';
|
||||
}
|
||||
},
|
||||
@{
|
||||
'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);
|
||||
'DisabledReason' = 'Neither the Icinga Agent nor the Icinga for Windows service are installed';
|
||||
'AdminMenu' = $TRUE;
|
||||
'Action' = @{
|
||||
'Command' = 'Disable-IcingaServiceRecovery';
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
22
lib/core/windows/Disable-IcingaServiceRecovery.psm1
Normal file
22
lib/core/windows/Disable-IcingaServiceRecovery.psm1
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
function Disable-IcingaServiceRecovery()
|
||||
{
|
||||
if ($null -ne (Get-Service 'icinga2')) {
|
||||
$ServiceStatus = Start-IcingaProcess -Executable 'sc.exe' -Arguments 'failure icinga2 reset=0 actions=none/0/none/0/none/0';
|
||||
|
||||
if ($ServiceStatus.ExitCode -ne 0) {
|
||||
Write-IcingaConsoleError -Message 'Failed to disable recover settings for service "icinga2": {0} {1}' -Objects $ServiceStatus.Message, $ServiceStatus.Error;
|
||||
} else {
|
||||
Write-IcingaConsoleNotice -Message 'Successfully disabled service recovery for service "icinga2"';
|
||||
}
|
||||
}
|
||||
|
||||
if ($null -ne (Get-Service 'icingapowershell')) {
|
||||
$ServiceStatus = Start-IcingaProcess -Executable 'sc.exe' -Arguments 'failure icingapowershell reset=0 actions=none/0/none/0/none/0';
|
||||
|
||||
if ($ServiceStatus.ExitCode -ne 0) {
|
||||
Write-IcingaConsoleError -Message 'Failed to disable recover settings for service "icingapowershell": {0} {1}' -Objects $ServiceStatus.Message, $ServiceStatus.Error;
|
||||
} else {
|
||||
Write-IcingaConsoleNotice -Message 'Successfully disabled service recovery for service "icingapowershell"';
|
||||
}
|
||||
}
|
||||
}
|
||||
22
lib/core/windows/Enable-IcingaServiceRecovery.psm1
Normal file
22
lib/core/windows/Enable-IcingaServiceRecovery.psm1
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
function Enable-IcingaServiceRecovery()
|
||||
{
|
||||
if ($null -ne (Get-Service 'icinga2')) {
|
||||
$ServiceStatus = Start-IcingaProcess -Executable 'sc.exe' -Arguments 'failure icinga2 reset=0 actions=restart/0/restart/0/restart/0';
|
||||
|
||||
if ($ServiceStatus.ExitCode -ne 0) {
|
||||
Write-IcingaConsoleError -Message 'Failed to enable recover settings for service "icinga2": {0} {1}' -Objects $ServiceStatus.Message, $ServiceStatus.Error;
|
||||
} else {
|
||||
Write-IcingaConsoleNotice -Message 'Successfully enabled service recovery for service "icinga2"';
|
||||
}
|
||||
}
|
||||
|
||||
if ($null -ne (Get-Service 'icingapowershell')) {
|
||||
$ServiceStatus = Start-IcingaProcess -Executable 'sc.exe' -Arguments 'failure icingapowershell reset=0 actions=restart/0/restart/0/restart/0';
|
||||
|
||||
if ($ServiceStatus.ExitCode -ne 0) {
|
||||
Write-IcingaConsoleError -Message 'Failed to enable recover settings for service "icingapowershell": {0} {1}' -Objects $ServiceStatus.Message, $ServiceStatus.Error;
|
||||
} else {
|
||||
Write-IcingaConsoleNotice -Message 'Successfully enabled service recovery for service "icingapowershell"';
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue