icinga-powershell-framework/lib/daemon/Add-IcingaForWindowsDaemon.psm1
2022-03-18 22:54:43 +01:00

28 lines
860 B
PowerShell

function Add-IcingaForWindowsDaemon()
{
try {
$EnabledDaemons = Get-IcingaBackgroundDaemons;
foreach ($daemon in $EnabledDaemons.Keys) {
Write-IcingaDebugMessage -Message 'Trying to enable background daemon' -Objects $daemon;
if (-Not (Test-IcingaFunction $daemon)) {
Write-IcingaEventMessage -EventId 1400 -Namespace 'Framework' $daemon;
continue;
}
$daemonArgs = $EnabledDaemons[$daemon];
Write-IcingaDebugMessage -Message 'Starting background daemon' -Objects $daemon, $daemonArgs;
& $daemon @daemonArgs;
}
} catch {
# Todo: Add exception handling
}
while ($TRUE) {
Start-Sleep -Seconds 1;
# Handle possible threads being frozen
Suspend-IcingaForWindowsFrozenThreads;
}
}