Skip to content

Commit

Permalink
Merge pull request #590 from Icinga:fix/background_service_registrati…
Browse files Browse the repository at this point in the history
…on_not_working

Fix: Background service registration

Fixes background service registration caused by migration task for v1.10.0 being executed even when no services were defined before
  • Loading branch information
LordHepipud committed Oct 18, 2022
2 parents 19e422e + d8f2a9a commit 9f91290
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
8 changes: 8 additions & 0 deletions doc/100-General/10-Changelog.md
Expand Up @@ -7,6 +7,14 @@ 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.1 (2022-27-10)

[Issue and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/27?closed=1)

### Bugfixes

* [#582](https://github.com/Icinga/icinga-powershell-framework/issues/582) Fixes background service registration caused by migration task for v1.10.0 being executed even when no services were defined before

## 1.10.0 (2022-08-30)

[Issue and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/23?closed=1)
Expand Down
37 changes: 25 additions & 12 deletions lib/core/framework/Invoke-IcingaForWindowsMigration.psm1
Expand Up @@ -52,28 +52,41 @@ function Invoke-IcingaForWindowsMigration()
# Convert the time intervals for the background daemon services from the previous index handling
# 1, 3, 5, 15 as example to 1m, 3m, 5m, 15m
$BackgroundServices = Get-IcingaPowerShellConfig -Path 'BackgroundDaemon.RegisteredServices';
[hashtable]$Output = @{ };

foreach ($service in $BackgroundServices.PSObject.Properties) {
[array]$ConvertedTimeIndex = @();

foreach ($interval in $service.Value.TimeIndexes) {
if (Test-Numeric $interval) {
$ConvertedTimeIndex += [string]::Format('{0}m', $interval);
} else {
$ConvertedTimeIndex = $interval;
# Only run this migration in case background services are defined
if ($null -ne $BackgroundServices) {
foreach ($service in $BackgroundServices.PSObject.Properties) {
[array]$ConvertedTimeIndex = @();

foreach ($interval in $service.Value.TimeIndexes) {
if (Test-Numeric $interval) {
$ConvertedTimeIndex += [string]::Format('{0}m', $interval);
} else {
$ConvertedTimeIndex = $interval;
}
}

$service.Value.TimeIndexes = $ConvertedTimeIndex;
}

$service.Value.TimeIndexes = $ConvertedTimeIndex;
Set-IcingaPowerShellConfig -Path 'BackgroundDaemon.RegisteredServices' -Value $BackgroundServices;
}

Set-IcingaPowerShellConfig -Path 'BackgroundDaemon.RegisteredServices' -Value $BackgroundServices;

Set-IcingaForWindowsMigration -MigrationVersion (New-IcingaVersionObject -Version '1.10.0');

if ($ServiceStatus -eq 'Running') {
Restart-IcingaWindowsService -Service 'icingapowershell';
}
}

if (Test-IcingaForWindowsMigration -MigrationVersion (New-IcingaVersionObject -Version '1.10.1')) {
Write-IcingaConsoleNotice 'Applying pending migrations required for Icinga for Windows v1.10.1';

# Fix Icinga for Windows v1.10.0 broken background service registration
if ($null -eq (Get-IcingaPowerShellConfig -Path 'BackgroundDaemon.RegisteredServices')) {
Remove-IcingaPowerShellConfig -Path 'BackgroundDaemon.RegisteredServices';
}

Set-IcingaForWindowsMigration -MigrationVersion (New-IcingaVersionObject -Version '1.10.1');
}
}

0 comments on commit 9f91290

Please sign in to comment.