Improves IMC update and uninstall handling for Framework

This commit is contained in:
Lord Hepipud 2022-08-26 09:55:25 +02:00
parent 29b3f925bd
commit adde8c0c81
8 changed files with 72 additions and 0 deletions

View file

@ -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)

View file

@ -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()

View file

@ -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;

View file

@ -175,4 +175,8 @@ function Install-Icinga()
}
}
}
if ($null -ne (Get-Command -Name 'Set-IcingaForWindowsManagementConsoleClosing' -ErrorAction SilentlyContinue)) {
Set-IcingaForWindowsManagementConsoleClosing -Completed;
}
}

View file

@ -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));
}

View file

@ -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;
}
}

View file

@ -0,0 +1,6 @@
function Test-IcingaForWindowsManagementConsoleUpdating()
{
$UpdateFile = Join-Path -Path (Get-IcingaCacheDir) -ChildPath 'framework.update';
return (Test-Path -Path $UpdateFile);
}

View file

@ -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) {