Repository navigation
Description
Description
When Windows Update Offload is enabled (Enable-IcingaWindowsUpdateOffload), the scheduled task
\Icinga\Icinga for Windows\Fetch Windows Updates is registered without an explicit
ExecutionTimeLimit, so Windows applies its default limit of 72 hours.
jobs\FetchWindowsUpdates.ps1 is designed to run forever (endless loop that refreshes the cache
every 10 minutes). After 72 hours the Task Scheduler terminates the process, and since the task
only has an At startup trigger, it is never started again until the next reboot.
From then on the cache file is no longer refreshed and Invoke-IcingaCheckUpdates goes
WARNING/CRITICAL on every host, e.g.:
Last Update Check: Value 5.98h is greater than threshold 30m
In our environment this happened on all Windows hosts at the same time.
Steps to reproduce
- Run
Enable-IcingaWindowsUpdateOffload - Wait more than 72 hours without rebooting the host
- The task is in state
Ready(notRunning) and theLast Update Checkof
Invoke-IcingaCheckUpdatesexceeds the 20m/30m thresholds
Evidence
PS> $t = Get-ScheduledTask -TaskName 'Fetch Windows Updates' -TaskPath '\Icinga\Icinga for Windows\'
PS> $t.Settings.ExecutionTimeLimit
PT72H
PS> $t.Triggers | Select-Object CimClass
Root/Microsoft/Windows/TaskScheduler:MSFT_TaskBootTrigger
Starting the task manually (Start-ScheduledTask) fixes the check until the next 72h limit is hit.
Cause
In lib/provider/updates/Register-IcingaWindowsScheduledTaskWindowsUpdates.psm1:
$TaskSettings = New-ScheduledTaskSettingsSet -DontStopIfGoingOnBatteries -AllowStartIfOnBatteries -StartWhenAvailable;
No -ExecutionTimeLimit is passed, so the Windows default (PT72H) is used, and the only trigger is
New-ScheduledTaskTrigger -AtStartup.
Suggested fix
Disable the execution time limit and add a recurring trigger, so the job is restarted if it ever
stops for any reason (IgnoreNew prevents parallel instances while it is running):
$TaskSettings = New-ScheduledTaskSettingsSet -DontStopIfGoingOnBatteries -AllowStartIfOnBatteries -StartWhenAvailable `
-ExecutionTimeLimit (New-TimeSpan -Seconds 0) -MultipleInstances IgnoreNew;
$TaskTrigger = @(
(New-ScheduledTaskTrigger -AtStartup),
(New-ScheduledTaskTrigger -Once -At (Get-Date).Date -RepetitionInterval (New-TimeSpan -Minutes 30) -RepetitionDuration (New-TimeSpan -Days 3650))
);
Workaround
Patch the existing task (we enforce this via Puppet):
$t = Get-ScheduledTask -TaskName 'Fetch Windows Updates' -TaskPath '\Icinga\Icinga for Windows\'
Set-ScheduledTask -TaskName $t.TaskName -TaskPath $t.TaskPath `
-Settings (New-ScheduledTaskSettingsSet -DontStopIfGoingOnBatteries -AllowStartIfOnBatteries -StartWhenAvailable -ExecutionTimeLimit (New-TimeSpan -Seconds 0) -MultipleInstances IgnoreNew) `
-Trigger @((New-ScheduledTaskTrigger -AtStartup), (New-ScheduledTaskTrigger -Once -At (Get-Date).Date -RepetitionInterval (New-TimeSpan -Minutes 30) -RepetitionDuration (New-TimeSpan -Days 3650)))
Start-ScheduledTask -TaskName $t.TaskName -TaskPath $t.TaskPath
Environment
- Icinga PowerShell Framework: 1.16.0
- Icinga PowerShell Plugins: 1.16.1
- Icinga 2 agent: 2.14.10
- OS: [p. ex. Windows Server 2022]
- Icinga 2 service user: NT AUTHORITY\NetworkService (reason for using the offload feature)
Activity