diff --git a/doc/100-General/10-Changelog.md b/doc/100-General/10-Changelog.md index 1ec50b9..b78d76f 100644 --- a/doc/100-General/10-Changelog.md +++ b/doc/100-General/10-Changelog.md @@ -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 diff --git a/lib/core/installer/Start-IcingaForWindowsInstallation.psm1 b/lib/core/installer/Start-IcingaForWindowsInstallation.psm1 index 36bd474..39f390f 100644 --- a/lib/core/installer/Start-IcingaForWindowsInstallation.psm1 +++ b/lib/core/installer/Start-IcingaForWindowsInstallation.psm1 @@ -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; diff --git a/lib/core/installer/menu/installation/AdvancedEntries.psm1 b/lib/core/installer/menu/installation/AdvancedEntries.psm1 index b1d9251..cafdd7e 100644 --- a/lib/core/installer/menu/installation/AdvancedEntries.psm1 +++ b/lib/core/installer/menu/installation/AdvancedEntries.psm1 @@ -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; diff --git a/lib/core/installer/menu/installation/framework/ServiceRecovery.psm1 b/lib/core/installer/menu/installation/framework/ServiceRecovery.psm1 new file mode 100644 index 0000000..93f7d27 --- /dev/null +++ b/lib/core/installer/menu/installation/framework/ServiceRecovery.psm1 @@ -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'; diff --git a/lib/core/installer/menu/manage/settings/services/ManageServices.psm1 b/lib/core/installer/menu/manage/settings/services/ManageServices.psm1 index 3699d19..dbc3828 100644 --- a/lib/core/installer/menu/manage/settings/services/ManageServices.psm1 +++ b/lib/core/installer/menu/manage/settings/services/ManageServices.psm1 @@ -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'; + } } ); } diff --git a/lib/core/windows/Disable-IcingaServiceRecovery.psm1 b/lib/core/windows/Disable-IcingaServiceRecovery.psm1 new file mode 100644 index 0000000..9a57817 --- /dev/null +++ b/lib/core/windows/Disable-IcingaServiceRecovery.psm1 @@ -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"'; + } + } +} diff --git a/lib/core/windows/Enable-IcingaServiceRecovery.psm1 b/lib/core/windows/Enable-IcingaServiceRecovery.psm1 new file mode 100644 index 0000000..0fd3313 --- /dev/null +++ b/lib/core/windows/Enable-IcingaServiceRecovery.psm1 @@ -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"'; + } + } +}