mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Merge pull request #318 from Icinga:feature/enforce_framework_cache
Feature: Always enforce Framework code caching To ensure we increase the performance of the loading and to introduce JEA profiles later on, we will now enforce the Icinga Framework Code cache starting with 1.6.0. By doing so, each new update will be forced to create a Framework Code Cache and only this file will be loaded during intialisation.
This commit is contained in:
commit
2583e82102
15 changed files with 46 additions and 226 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -6,3 +6,4 @@ cache/*
|
|||
*.log
|
||||
|
||||
!cache/README.md
|
||||
!cache/framework_cache.psm1
|
||||
15
cache/framework_cache.psm1
vendored
Normal file
15
cache/framework_cache.psm1
vendored
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<#
|
||||
### Note ###
|
||||
|
||||
This file is shipping plain with Icinga for Windows for each version.
|
||||
Once the module is loaded, this content will entirely be replaced with
|
||||
all modules and components shipped by the Icinga PowerShell Framework.
|
||||
|
||||
Manually enabling the feature is no longer required.
|
||||
#>
|
||||
|
||||
$Global:Icinga = @{
|
||||
'RebuildCache' = $TRUE;
|
||||
};
|
||||
|
||||
Write-IcingaFrameworkCodeCache;
|
||||
|
|
@ -23,6 +23,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
|
|||
* [#306](https://github.com/Icinga/icinga-powershell-framework/pull/306) Adds new Cmdlet `Exit-IcingaThrowCritical` to throw critical exit with a custom message, either by force or by using string filtering and adds storing of plugin exit codes internally
|
||||
* [#314](https://github.com/Icinga/icinga-powershell-framework/pull/314) Adds support to configure on which address TCP sockets are created on, defaults to `loopback` interface
|
||||
* [#316](https://github.com/Icinga/icinga-powershell-framework/pull/316) The reconfigure menu was previously present inside the Icinga Agent sub-menu and is now moved to the main installation menu for the Management Console
|
||||
* [#318](https://github.com/Icinga/icinga-powershell-framework/pull/318) We always enforce the Icinga Framework Code caching now and ship a plain file to build the cache on first loading
|
||||
|
||||
## 1.5.2 (2021-07-09)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,45 +1,21 @@
|
|||
# Enable Framework Code Caching
|
||||
# Framework Code Caching
|
||||
|
||||
On certain systems with fewer CPU cores, there might be an impact while running Icinga for Windows because of long loading times for the Icinga PowerShell Framework. To mitigate this issue, we added the possibility to create a code cache file for the entire Icinga PowerShell Framework.
|
||||
By default, Icinga for Windows will compile all module files into a single cache file for quicker and easier loading. This ensures, that during startup all functions are available and can be used in combination with JEA profiles.
|
||||
|
||||
What it does is to load every single module and content file into one single `cache.psm1` file which is loaded in case the caching is enabled.
|
||||
The location of the cache file is at
|
||||
|
||||
```
|
||||
.\cache\framework_cache.psm1
|
||||
```
|
||||
|
||||
## Pre-Cautions
|
||||
|
||||
By enabling this feature, you will have to generate a new cache file whenever you apply changes to any code for the Icinga PowerShell Framework. This can be done by running the Cmdlet
|
||||
In case you are running custom modifications to the Framework or apply manual patches, you will **always** have to re-write the Icinga for Windows cache file! During upgrades by using the Icinga for Windows Cmdlets, the cache file is updated automatically.
|
||||
|
||||
## Updating Cache File
|
||||
|
||||
To re-write the cache file and update it to the latest version manually, you can use the following command:
|
||||
|
||||
```powershell
|
||||
Write-IcingaFrameworkCodeCache
|
||||
```
|
||||
|
||||
Please note that the code cache feature must be enabled first.
|
||||
|
||||
In case you upgrade to a newer version of the Icinga PowerShell Framework, you will only require to manually proceed in case the code cache feature was disabled beforehand. In case the code cache feature is enabled during the upgrade, the cache file will be generated and updated automatically.
|
||||
|
||||
## Enable Icinga Framework Code Cache
|
||||
|
||||
To enable the Icinga PowerShell Framework code cache, simply run the following command within an Icinga Shell:
|
||||
|
||||
```powershell
|
||||
Enable-IcingaFrameworkCodeCache
|
||||
```
|
||||
|
||||
Once activated, you should make sure to generate a new cache file before using the Framework:
|
||||
|
||||
```powershell
|
||||
Write-IcingaFrameworkCodeCache
|
||||
```
|
||||
|
||||
If you leave the code caching feature enabled, future updates of the Framework will automatically generate a new cache file. If you disabled the feature in-between, please write the cache file manually.
|
||||
|
||||
In case no cache file is present while the feature is activated, a cache file is generated on the first use of `Use-Icinga` or `icinga`.
|
||||
|
||||
## Disable Icinga Framework Code Cache
|
||||
|
||||
To disable the code caching feature again, you can simply run
|
||||
|
||||
```powershell
|
||||
Disable-IcingaFrameworkCodeCache
|
||||
```
|
||||
|
||||
Please note that even though the cache file is no longer loaded it still remains. Therefor you will have to manually use `Write-IcingaFrameworkCodeCache` in case you activate the feature later again. This is especially required if you update the Icinga PowerShell Framework while the feature was disabled.
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ Which version of the "Icinga Framework" do you want to install? (release/snapsho
|
|||
[Notice]: Unblocking Icinga PowerShell Files
|
||||
[Notice]: Cleaning temporary content
|
||||
[Notice]: Updating Framework cache file
|
||||
[Notice]: The code caching feature is currently not enabled. You can enable it with "Enable-IcingaFrameworkCodeCache"
|
||||
[Notice]: Framework update has been completed. Please start a new PowerShell instance now to complete the update
|
||||
[Passed]: Icinga Agent service is installed
|
||||
[Passed]: The specified user "NT Authority\NetworkService" is allowed to run as service
|
||||
|
|
|
|||
|
|
@ -8,32 +8,7 @@
|
|||
Description = 'Icinga for Windows module which allows to entirely monitor the Windows Host system.'
|
||||
PowerShellVersion = '4.0'
|
||||
NestedModules = @(
|
||||
'.\lib\core\framework\Get-IcingaFrameworkCodeCache.psm1',
|
||||
'.\lib\config\Get-IcingaPowerShellConfig.psm1',
|
||||
'.\lib\config\Read-IcingaPowerShellConfig.psm1',
|
||||
'.\lib\config\Test-IcingaPowerShellConfigItem.psm1',
|
||||
'.\lib\core\logging\Write-IcingaConsoleOutput.psm1',
|
||||
'.\lib\core\logging\Write-IcingaConsoleNotice.psm1',
|
||||
'.\lib\core\logging\Write-IcingaConsoleWarning.psm1',
|
||||
'.\lib\core\tools\Read-IcingaFileContent.psm1',
|
||||
'.\lib\core\framework\Invoke-IcingaInternalServiceCall.psm1',
|
||||
'.\lib\core\framework\Get-IcingaFrameworkApiChecks.psm1',
|
||||
'.\lib\daemon\Get-IcingaBackgroundDaemons.psm1',
|
||||
'.\lib\webserver\Enable-IcingaUntrustedCertificateValidation.psm1',
|
||||
'.\lib\core\logging\Write-IcingaEventMessage.psm1',
|
||||
'.\lib\icinga\plugin\Exit-IcingaExecutePlugin.psm1',
|
||||
'.\lib\icinga\exception\Exit-IcingaPluginNotInstalled.psm1',
|
||||
'.\lib\icinga\exception\Exit-IcingaThrowException.psm1',
|
||||
'.\lib\web\Set-IcingaTLSVersion.psm1',
|
||||
'.\lib\web\Disable-IcingaProgressPreference.psm1',
|
||||
'.\lib\core\tools\New-IcingaNewLine.psm1',
|
||||
'.\lib\core\logging\Write-IcingaConsolePlain.psm1',
|
||||
'.\lib\core\tools\Test-IcingaFunction.psm1',
|
||||
'.\lib\core\tools\Write-IcingaConsoleHeader.psm1',
|
||||
'.\lib\core\framework\Test-IcingaFrameworkConsoleOutput.psm1',
|
||||
'.\lib\core\tools\ConvertTo-IcingaSecureString.psm1',
|
||||
'.\lib\core\tools\ConvertTo-JsonUTF8Bytes.psm1',
|
||||
'.\lib\core\tools\ConvertFrom-JsonUTF8.psm1'
|
||||
'.\cache\framework_cache.psm1'
|
||||
)
|
||||
FunctionsToExport = @(
|
||||
'Use-Icinga',
|
||||
|
|
@ -52,7 +27,6 @@
|
|||
'Get-IcingaPowerShellModuleFile',
|
||||
'Start-IcingaShellAsUser',
|
||||
'Get-IcingaPowerShellConfig',
|
||||
'Get-IcingaFrameworkCodeCache',
|
||||
'Read-IcingaPowerShellConfig',
|
||||
'Test-IcingaPowerShellConfigItem',
|
||||
'Write-IcingaConsoleOutput',
|
||||
|
|
|
|||
|
|
@ -17,6 +17,11 @@ function Use-Icinga()
|
|||
[switch]$Minimal = $FALSE
|
||||
);
|
||||
|
||||
if ($null -ne $Global:Icinga -And $Global:Icinga.ContainsKey('RebuildCache') -And $Global:Icinga.RebuildCache) {
|
||||
Remove-Module 'icinga-powershell-framework';
|
||||
Import-Module (Get-IcingaFrameworkCodeCacheFile) -Global -Force;
|
||||
}
|
||||
|
||||
Disable-IcingaProgressPreference;
|
||||
|
||||
if ($Minimal) {
|
||||
|
|
@ -42,9 +47,7 @@ function Use-Icinga()
|
|||
Use-IcingaPlugins;
|
||||
}
|
||||
|
||||
if ((Test-Path (Get-IcingaFrameworkCodeCacheFile)) -eq $FALSE -And (Get-IcingaFrameworkCodeCache)) {
|
||||
Write-IcingaFrameworkCodeCache;
|
||||
}
|
||||
Write-IcingaFrameworkCodeCache;
|
||||
|
||||
# This function will allow us to load this entire module including possible
|
||||
# actions, making it available within our shell environment
|
||||
|
|
@ -109,11 +112,7 @@ function Get-IcingaFrameworkCodeCacheFile()
|
|||
|
||||
function Write-IcingaFrameworkCodeCache()
|
||||
{
|
||||
if (Get-IcingaFrameworkCodeCache) {
|
||||
Import-IcingaLib '\' -Init -CompileCache;
|
||||
} else {
|
||||
Write-IcingaConsoleNotice 'The code caching feature is currently not enabled. You can enable it with "Enable-IcingaFrameworkCodeCache"';
|
||||
}
|
||||
Import-IcingaLib '\' -Init -CompileCache;
|
||||
}
|
||||
|
||||
function Import-IcingaLib()
|
||||
|
|
@ -129,16 +128,15 @@ function Import-IcingaLib()
|
|||
[switch]$CompileCache
|
||||
);
|
||||
|
||||
|
||||
# This is just to only allow a global loading of the module. Import-IcingaLib is ignored on every other
|
||||
# location. It is just there to give a basic idea within commands, of which functions are used
|
||||
if ($Init -eq $FALSE) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$CacheFile = Get-IcingaFrameworkCodeCacheFile;
|
||||
|
||||
if ($Custom -eq $FALSE -And $CompileCache -eq $FALSE -And (Test-Path $CacheFile) -And (Get-IcingaFrameworkCodeCache)) {
|
||||
if ($Custom -eq $FALSE -And $CompileCache -eq $FALSE -And (Test-Path $CacheFile)) {
|
||||
Import-Module $CacheFile -Global;
|
||||
return;
|
||||
}
|
||||
|
|
@ -361,8 +359,8 @@ function Invoke-IcingaCommand()
|
|||
'User environment $UserDomain\$Username'
|
||||
);
|
||||
|
||||
if (Get-IcingaFrameworkCodeCache) {
|
||||
$Headers += [string]::Format('Note: Icinga Framework Code Caching is enabled');
|
||||
if ($null -eq (Get-Command -Name 'Write-IcingaConsoleHeader' -ErrorAction SilentlyContinue)) {
|
||||
Use-Icinga;
|
||||
}
|
||||
|
||||
Write-IcingaConsoleHeader -HeaderLines $Headers;
|
||||
|
|
|
|||
|
|
@ -1,24 +0,0 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Disables the feature to cache all functions into a single file,
|
||||
allowing quicker loading times of the Icinga PowerShell Framework
|
||||
.DESCRIPTION
|
||||
Disables the feature to cache all functions into a single file,
|
||||
allowing quicker loading times of the Icinga PowerShell Framework
|
||||
.FUNCTIONALITY
|
||||
Disables the Icinga for Windows code caching
|
||||
.EXAMPLE
|
||||
PS>Disable-IcingaFrameworkCodeCache;
|
||||
.LINK
|
||||
https://github.com/Icinga/icinga-powershell-framework
|
||||
#>
|
||||
|
||||
function Disable-IcingaFrameworkCodeCache()
|
||||
{
|
||||
Set-IcingaPowerShellConfig -Path 'Framework.CodeCaching' -Value $FALSE;
|
||||
|
||||
# Remove the cache file in case it exists and the feature is disabled
|
||||
if (Test-Path -Path (Get-IcingaFrameworkCodeCacheFile)) {
|
||||
Remove-ItemSecure -Path (Get-IcingaFrameworkCodeCacheFile) -Force | Out-Null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Enables the feature to cache all functions into a single file,
|
||||
allowing quicker loading times of the Icinga PowerShell Framework
|
||||
.DESCRIPTION
|
||||
Enables the feature to cache all functions into a single file,
|
||||
allowing quicker loading times of the Icinga PowerShell Framework
|
||||
.FUNCTIONALITY
|
||||
Enables the Icinga for Windows code caching
|
||||
.EXAMPLE
|
||||
PS>Enable-IcingaFrameworkCodeCache;
|
||||
.LINK
|
||||
https://github.com/Icinga/icinga-powershell-framework
|
||||
#>
|
||||
|
||||
function Enable-IcingaFrameworkCodeCache()
|
||||
{
|
||||
Set-IcingaPowerShellConfig -Path 'Framework.CodeCaching' -Value $TRUE;
|
||||
|
||||
Write-IcingaConsoleWarning 'Please run "Write-IcingaFrameworkCodeCache" in addition to ensure your cache is updated. This should be done after each update of the Framework in case the feature was disabled during the update run.';
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Fetches the current enable/disable state of the feature
|
||||
for caching the Icinga PowerShell Framework code
|
||||
.DESCRIPTION
|
||||
Fetches the current enable/disable state of the feature
|
||||
for caching the Icinga PowerShell Framework code
|
||||
.FUNCTIONALITY
|
||||
Get the current code caching configuration of the
|
||||
Icinga PowerShell Framework
|
||||
.EXAMPLE
|
||||
PS>Get-IcingaFrameworkCodeCache;
|
||||
.LINK
|
||||
https://github.com/Icinga/icinga-powershell-framework
|
||||
.OUTPUTS
|
||||
System.Boolean
|
||||
#>
|
||||
|
||||
function Get-IcingaFrameworkCodeCache()
|
||||
{
|
||||
$CodeCaching = Get-IcingaPowerShellConfig -Path 'Framework.CodeCaching';
|
||||
|
||||
if ($null -eq $CodeCaching) {
|
||||
return $FALSE;
|
||||
}
|
||||
|
||||
return $CodeCaching;
|
||||
}
|
||||
|
|
@ -43,9 +43,6 @@ function Start-IcingaForWindowsInstallation()
|
|||
$IcingaEndpoints = Get-IcingaForWindowsInstallerValuesFromStep -InstallerStep 'Show-IcingaForWindowsInstallerMenuEnterIcingaParentNodes';
|
||||
$IcingaPort = Get-IcingaForWindowsInstallerValuesFromStep -InstallerStep 'Show-IcingaForWindowsInstallationMenuEnterIcingaPort';
|
||||
|
||||
# Icinga for Windows PowerShell Framework
|
||||
$CodeCacheType = Get-IcingaForWindowsInstallerStepSelection -InstallerStep 'Show-IcingaForWindowsManagementConsoleEnableCodeCache';
|
||||
|
||||
$Hostname = '';
|
||||
$GlobalZones = @();
|
||||
$IcingaParentAddresses = @();
|
||||
|
|
@ -224,21 +221,7 @@ function Start-IcingaForWindowsInstallation()
|
|||
}
|
||||
}
|
||||
|
||||
switch ($CodeCacheType) {
|
||||
'0' {
|
||||
# Enable Code Cache
|
||||
Enable-IcingaFrameworkCodeCache;
|
||||
Write-IcingaConsoleNotice 'Writing Icinga Framework Code Cache file';
|
||||
Write-IcingaFrameworkCodeCache;
|
||||
break;
|
||||
};
|
||||
'1' {
|
||||
# Disable Code Cache
|
||||
Disable-IcingaFrameworkCodeCache;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Write-IcingaFrameworkCodeCache;
|
||||
Test-IcingaAgent;
|
||||
|
||||
if ($InstallAgent) {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ function Add-IcingaForWindowsInstallationAdvancedEntries()
|
|||
Show-IcingaForWindowsInstallerMenuSelectIcingaPluginsSource -Automated -Advanced;
|
||||
Show-IcingaForWindowsInstallerMenuSelectWindowsServiceSource -Automated -Advanced;
|
||||
Show-IcingaForWindowsInstallationMenuEnterWindowsServiceDirectory -Automated -Advanced;
|
||||
Show-IcingaForWindowsManagementConsoleEnableCodeCache -Automated -Advanced;
|
||||
|
||||
Enable-IcingaFrameworkConsoleOutput;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
function Show-IcingaForWindowsManagementConsoleEnableCodeCache()
|
||||
{
|
||||
param (
|
||||
[array]$Value = @(),
|
||||
[string]$DefaultInput = '0',
|
||||
[switch]$JumpToSummary = $FALSE,
|
||||
[switch]$Automated = $FALSE,
|
||||
[switch]$Advanced = $FALSE
|
||||
);
|
||||
|
||||
Show-IcingaForWindowsInstallerMenu `
|
||||
-Header 'Do you want to enable the Icinga Framework Code Cache?' `
|
||||
-Entries @(
|
||||
@{
|
||||
'Caption' = 'Enable Icinga Framework Code Cache ';
|
||||
'Command' = 'Show-IcingaForWindowsInstallerConfigurationSummary';
|
||||
'Help' = 'Enables the Icinga Framework Code Cache feature during installation to decrease the loading time of the Icinga Framework. Please note that for each custom modification you do on the Icinga Framework afterwards, you will have to call "Write-IcingaFrameworkCodeCache" to rebuild the cache';
|
||||
},
|
||||
@{
|
||||
'Caption' = 'Disable Icinga Framework Code Cache';
|
||||
'Command' = 'Show-IcingaForWindowsInstallerConfigurationSummary';
|
||||
'Help' = 'Does not enable the Icinga Framework Code Cache and disables it during the installation process';
|
||||
}
|
||||
) `
|
||||
-DefaultIndex $DefaultInput `
|
||||
-JumpToSummary:$FALSE `
|
||||
-ConfigElement `
|
||||
-Automated:$Automated `
|
||||
-Advanced:$Advanced;
|
||||
}
|
||||
|
||||
Set-Alias -Name 'IfW-CodeCache' -Value 'Show-IcingaForWindowsManagementConsoleEnableCodeCache';
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
function Show-IcingaForWindowsManagementConsoleManageFramework()
|
||||
{
|
||||
$FrameworkDebug = Get-IcingaFrameworkDebugMode;
|
||||
$FrameworkCodeCache = Get-IcingaFrameworkCodeCache;
|
||||
$IcingaService = Get-Service 'icingapowershell' -ErrorAction SilentlyContinue;
|
||||
$AdminShell = $global:Icinga.InstallWizard.AdminShell;
|
||||
$ServiceStatus = $null;
|
||||
|
|
@ -30,21 +29,10 @@ function Show-IcingaForWindowsManagementConsoleManageFramework()
|
|||
}
|
||||
},
|
||||
@{
|
||||
'Caption' = ([string]::Format('Framework Code Cache: {0}', (& { if ($FrameworkCodeCache) { 'Enabled' } else { 'Disabled' } } )));
|
||||
'Command' = 'Show-IcingaForWindowsManagementConsoleManageFramework';
|
||||
'Help' = 'Disable or enable the Icinga PowerShell Framework Code cache feature. The code cache is written automatically once it is enabled';
|
||||
'Disabled' = $FALSE;
|
||||
'Action' = @{
|
||||
'Command' = 'Invoke-IcingaForWindowsMangementConsoleToogleFrameworkCodeCache';
|
||||
'Arguments' = @{ };
|
||||
}
|
||||
},
|
||||
@{
|
||||
'Caption' = 'Update Framework Code Cache';
|
||||
'Command' = 'Show-IcingaForWindowsManagementConsoleManageFramework';
|
||||
'Help' = 'Updates the Icinga PowerShell Framework Code Cache';
|
||||
'Disabled' = (-Not ($FrameworkCodeCache));
|
||||
'Action' = @{
|
||||
'Caption' = 'Update Framework Code Cache';
|
||||
'Command' = 'Show-IcingaForWindowsManagementConsoleManageFramework';
|
||||
'Help' = 'Updates the Icinga PowerShell Framework Code Cache';
|
||||
'Action' = @{
|
||||
'Command' = 'Write-IcingaFrameworkCodeCache';
|
||||
'Arguments' = @{ };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
function Invoke-IcingaForWindowsMangementConsoleToogleFrameworkCodeCache()
|
||||
{
|
||||
if (Get-IcingaFrameworkCodeCache) {
|
||||
Disable-IcingaFrameworkCodeCache;
|
||||
} else {
|
||||
Enable-IcingaFrameworkCodeCache;
|
||||
Write-IcingaFrameworkCodeCache;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue