From 5daccac37466c089185d7424507edd4f9fa5b4af Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Tue, 23 Aug 2022 16:37:18 +0200 Subject: [PATCH] Fixes exception for service recovery if service was not installed --- doc/100-General/10-Changelog.md | 1 + lib/core/windows/Disable-IcingaServiceRecovery.psm1 | 4 ++-- lib/core/windows/Enable-IcingaServiceRecovery.psm1 | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/100-General/10-Changelog.md b/doc/100-General/10-Changelog.md index de976ee..131d135 100644 --- a/doc/100-General/10-Changelog.md +++ b/doc/100-General/10-Changelog.md @@ -22,6 +22,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic * [#524](https://github.com/Icinga/icinga-powershell-framework/issues/524) Fixes uninstallation process by improving the location handling of PowerShell instances with Icinga IMC or Shell * [#545](https://github.com/Icinga/icinga-powershell-framework/issues/545) Fixes `RemoteSource` being cleared within repository `.json` files during `Update-IcingaRepository` tasks * [#552](https://github.com/Icinga/icinga-powershell-framework/pull/552) Fixes file encoding for Icinga for Windows v1.10.0 to ensure the cache is always properly created with the correct encoding +* [#553](https://github.com/Icinga/icinga-powershell-framework/pull/553) Fixes an exception caused by service recovery setting, if the required service was not installed before ### Enhancements diff --git a/lib/core/windows/Disable-IcingaServiceRecovery.psm1 b/lib/core/windows/Disable-IcingaServiceRecovery.psm1 index 9a57817..678c5bf 100644 --- a/lib/core/windows/Disable-IcingaServiceRecovery.psm1 +++ b/lib/core/windows/Disable-IcingaServiceRecovery.psm1 @@ -1,6 +1,6 @@ function Disable-IcingaServiceRecovery() { - if ($null -ne (Get-Service 'icinga2')) { + if ($null -ne (Get-Service 'icinga2' -ErrorAction SilentlyContinue)) { $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')) { + if ($null -ne (Get-Service 'icingapowershell' -ErrorAction SilentlyContinue)) { $ServiceStatus = Start-IcingaProcess -Executable 'sc.exe' -Arguments 'failure icingapowershell reset=0 actions=none/0/none/0/none/0'; if ($ServiceStatus.ExitCode -ne 0) { diff --git a/lib/core/windows/Enable-IcingaServiceRecovery.psm1 b/lib/core/windows/Enable-IcingaServiceRecovery.psm1 index 0fd3313..94c4c6d 100644 --- a/lib/core/windows/Enable-IcingaServiceRecovery.psm1 +++ b/lib/core/windows/Enable-IcingaServiceRecovery.psm1 @@ -1,6 +1,6 @@ function Enable-IcingaServiceRecovery() { - if ($null -ne (Get-Service 'icinga2')) { + if ($null -ne (Get-Service 'icinga2' -ErrorAction SilentlyContinue)) { $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')) { + if ($null -ne (Get-Service 'icingapowershell' -ErrorAction SilentlyContinue)) { $ServiceStatus = Start-IcingaProcess -Executable 'sc.exe' -Arguments 'failure icingapowershell reset=0 actions=restart/0/restart/0/restart/0'; if ($ServiceStatus.ExitCode -ne 0) {