diff --git a/doc/100-General/10-Changelog.md b/doc/100-General/10-Changelog.md index 1fa65c4..035e2f1 100644 --- a/doc/100-General/10-Changelog.md +++ b/doc/100-General/10-Changelog.md @@ -36,6 +36,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic * [#531](https://github.com/Icinga/icinga-powershell-framework/pull/531) Adds `Test-IcingaStateFile` and `Repair-IcingaStateFile`, which is integrated into `Test-IcingaAgent`, to ensure the Icinga Agent state file is healthy and not corrupt, causing the Icinga Agent to fail on start * [#534](https://github.com/Icinga/icinga-powershell-framework/pull/534) Improves Icinga and Director configuration generator, by wrapping PowerShell arrays inside `@()` instead of simply writing them comma separated * [#536](https://github.com/Icinga/icinga-powershell-framework/pull/536) Adds new function `Test-IcingaArrayFilter` for easier include and exclude filtering during plugin runtime and to allow filtering of array content for intended values only +* [#560](https://github.com/Icinga/icinga-powershell-framework/pull/560) Improves handling for Icinga Management Console which will now terminate itself during full uninstallation and restarts after updating the Icinga PowerShell Framework, to apply changes directly ## 1.9.2 (2022-06-03) diff --git a/icinga-powershell-framework.psm1 b/icinga-powershell-framework.psm1 index d3cbbfe..6896d84 100644 --- a/icinga-powershell-framework.psm1 +++ b/icinga-powershell-framework.psm1 @@ -252,6 +252,9 @@ function Invoke-IcingaCommand() -FileName 'icinga-powershell-framework.psd1' ` -BindingVariable IcingaFrameworkData; + # Ensure we always remove the update file in case present + Set-IcingaForWindowsManagementConsoleUpdating -Completed; + # Print a header informing our user that loaded the Icinga Framework with a specific # version. We can also skip the header by using $SKipHeader if ([string]::IsNullOrEmpty($ScriptBlock) -And $SkipHeader -eq $FALSE -And $Shell) { @@ -335,6 +338,24 @@ function Invoke-IcingaCommand() if (Test-Path $PSScriptRoot) { Set-Location $PSScriptRoot; } + + # In case we applied updates to the Framework while inside the IMC -> reopen it + if (Test-IcingaForWindowsManagementConsoleUpdating) { + Set-IcingaForWindowsManagementConsoleUpdating -Completed; + + # Use the same arguments again to open the IMC + $IMCReopenArguments = @{ + 'ScriptBlock' = $ScriptBlock; + 'SkipHeader' = $SkipHeader; + 'Manage' = $Manage; + 'Shell' = $Shell; + 'RebuildCache' = $RebuildCache; + 'DeveloperMode' = $DeveloperMode; + 'ArgumentList' = $ArgumentList; + }; + + Invoke-IcingaCommand @IMCReopenArguments; + } } function Start-IcingaShellAsUser() diff --git a/lib/core/framework/Uninstall-IcingaForWindows.psm1 b/lib/core/framework/Uninstall-IcingaForWindows.psm1 index d3469cd..639d512 100644 --- a/lib/core/framework/Uninstall-IcingaForWindows.psm1 +++ b/lib/core/framework/Uninstall-IcingaForWindows.psm1 @@ -55,6 +55,8 @@ function Uninstall-IcingaForWindows() if ($ComponentsOnly -eq $FALSE) { Write-IcingaConsoleNotice 'Uninstalling Icinga for Windows EventLog'; Unregister-IcingaEventLog; + # Ensure we close the IMC in case being open and we uninstall the Framework + Set-IcingaForWindowsManagementConsoleClosing; } Write-IcingaConsoleNotice 'Uninstalling Icinga for Windows service'; Uninstall-IcingaForWindowsService -RemoveFiles | Out-Null; diff --git a/lib/core/installer/Install-Icinga.psm1 b/lib/core/installer/Install-Icinga.psm1 index 7c9e676..9e9cb24 100644 --- a/lib/core/installer/Install-Icinga.psm1 +++ b/lib/core/installer/Install-Icinga.psm1 @@ -175,4 +175,8 @@ function Install-Icinga() } } } + + if ($null -ne (Get-Command -Name 'Set-IcingaForWindowsManagementConsoleClosing' -ErrorAction SilentlyContinue)) { + Set-IcingaForWindowsManagementConsoleClosing -Completed; + } } diff --git a/lib/core/installer/tools/SetCloseIMC.psm1 b/lib/core/installer/tools/SetCloseIMC.psm1 new file mode 100644 index 0000000..03d1638 --- /dev/null +++ b/lib/core/installer/tools/SetCloseIMC.psm1 @@ -0,0 +1,20 @@ +function Set-IcingaForWindowsManagementConsoleClosing() +{ + param ( + [switch]$Completed = $FALSE + ); + + if ($null -eq $Global:Icinga) { + return; + } + + if ($Global:Icinga.ContainsKey('InstallWizard') -eq $FALSE) { + return; + } + + if ($Global:Icinga.InstallWizard.ContainsKey('Closing') -eq $FALSE) { + return; + } + + $global:Icinga.InstallWizard.Closing = (-Not ([bool]$Completed)); +} diff --git a/lib/core/installer/tools/SetUpdatingIMC.psm1 b/lib/core/installer/tools/SetUpdatingIMC.psm1 new file mode 100644 index 0000000..76ae3e9 --- /dev/null +++ b/lib/core/installer/tools/SetUpdatingIMC.psm1 @@ -0,0 +1,15 @@ +function Set-IcingaForWindowsManagementConsoleUpdating() +{ + param ( + [switch]$Completed = $FALSE + ); + + Set-IcingaForWindowsManagementConsoleClosing; + + $UpdateFile = Join-Path -Path (Get-IcingaCacheDir) -ChildPath 'framework.update'; + if ($Completed) { + Remove-ItemSecure -Path $UpdateFile -Force -Retries 5 | Out-Null; + } else { + New-Item -Path $UpdateFile -ItemType File -Force | Out-Null; + } +} diff --git a/lib/core/installer/tools/TestUpdatingIMC.psm1 b/lib/core/installer/tools/TestUpdatingIMC.psm1 new file mode 100644 index 0000000..4ea2a48 --- /dev/null +++ b/lib/core/installer/tools/TestUpdatingIMC.psm1 @@ -0,0 +1,6 @@ +function Test-IcingaForWindowsManagementConsoleUpdating() +{ + $UpdateFile = Join-Path -Path (Get-IcingaCacheDir) -ChildPath 'framework.update'; + + return (Test-Path -Path $UpdateFile); +} diff --git a/lib/core/repository/Install-IcingaComponent.psm1 b/lib/core/repository/Install-IcingaComponent.psm1 index 52fd6c4..58a70d8 100644 --- a/lib/core/repository/Install-IcingaComponent.psm1 +++ b/lib/core/repository/Install-IcingaComponent.psm1 @@ -165,6 +165,9 @@ function Install-IcingaComponent() Stop-IcingaService 'icinga2'; Start-Sleep -Seconds 1; } + + # Ensure we close the IMC in case we do some updates on the Framework + Set-IcingaForWindowsManagementConsoleUpdating; } if ((Test-Path $ComponentFolder) -eq $FALSE) {