Add support to keep PowerShell open while running as daemon

This commit is contained in:
Lord Hepipud 2019-10-31 13:41:05 +01:00
parent 51042d6c0e
commit 0200b21ac9

View file

@ -1,5 +1,9 @@
function Start-IcingaPowerShellDaemon() function Start-IcingaPowerShellDaemon()
{ {
param(
[switch]$RunAsService
);
$ScriptBlock = { $ScriptBlock = {
param($IcingaDaemonData); param($IcingaDaemonData);
@ -32,4 +36,10 @@ function Start-IcingaPowerShellDaemon()
$global:IcingaDaemonData.Add('Config', (Read-IcingaPowerShellConfig)); $global:IcingaDaemonData.Add('Config', (Read-IcingaPowerShellConfig));
New-IcingaThreadInstance -Name "Icinga_PowerShell_Background_Daemon" -ThreadPool $IcingaDaemonData.IcingaThreadPool.BackgroundPool -ScriptBlock $ScriptBlock -Arguments @( $global:IcingaDaemonData ) -Start; New-IcingaThreadInstance -Name "Icinga_PowerShell_Background_Daemon" -ThreadPool $IcingaDaemonData.IcingaThreadPool.BackgroundPool -ScriptBlock $ScriptBlock -Arguments @( $global:IcingaDaemonData ) -Start;
if ($RunAsService) {
while ($TRUE) {
Start-Sleep -Seconds 100;
}
}
} }