Workaround dotnet issue 50020: Windows container service bug

This commit is contained in:
Jake Friedman 2021-04-27 11:17:02 -07:00
Родитель 07d1a29c5b
Коммит 51c113eb72
3 изменённых файлов: 39 добавлений и 13 удалений

Просмотреть файл

@ -8,7 +8,7 @@
description="Factory Orchestrator Service"
displayName="Factory Orchestrator Service"
errorControl="normal"
imagePath="%systemroot%\system32\manufacturing\FactoryOrchestrator\Microsoft.FactoryOrchestrator.Service.exe action:run"
imagePath="%systemroot%\system32\manufacturing\FactoryOrchestrator\Microsoft.FactoryOrchestrator.Service.exe -IsService"
name="Microsoft.FactoryOrchestrator.Service"
objectName="LocalSystem"
start="auto"

Просмотреть файл

@ -56,7 +56,7 @@ else
}
else
{
$null = New-Service -Name "Microsoft.FactoryOrchestrator" -BinaryPathName "$installdir\Microsoft.FactoryOrchestrator.Service.exe" -Description "Factory Orchestrator service version $Version$" -StartupType Manual
$null = New-Service -Name "Microsoft.FactoryOrchestrator" -BinaryPathName "$installdir\Microsoft.FactoryOrchestrator.Service.exe -IsService" -Description "Factory Orchestrator service version $Version$" -StartupType Manual
}
Write-Host "Factory Orchestrator service version $Version$ is installed to `"$installdir`" and configured as a Windows service!`n"

Просмотреть файл

@ -16,7 +16,9 @@ using JKang.IpcServiceFramework.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Hosting.WindowsServices;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.EventLog;
using Microsoft.FactoryOrchestrator.Client;
using Microsoft.FactoryOrchestrator.Core;
using Microsoft.FactoryOrchestrator.Server;
@ -107,18 +109,42 @@ namespace Microsoft.FactoryOrchestrator.Service
public static void Main(string[] args)
{
Host.CreateDefaultBuilder(null).UseSystemd().UseWindowsService().ConfigureServices((hostContext, services) =>
#if DEBUG
var _logLevel = LogLevel.Debug;
#else
var _logLevel = LogLevel.Information;
#endif
var hostBuilder = Host.CreateDefaultBuilder(null).UseSystemd().ConfigureServices((hostContext, services) =>
{
services.AddHostedService<Worker>();
}).ConfigureLogging(builder =>
{
#if DEBUG
var _logLevel = LogLevel.Debug;
#else
var _logLevel = LogLevel.Information;
#endif
builder.SetMinimumLevel(_logLevel).AddConsole().AddProvider(new LogFileProvider());
}).Build().Run();
});
bool isService = ((args != null) && (args.Length > 0));
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && isService)
{
hostBuilder.UseContentRoot(AppContext.BaseDirectory);
hostBuilder.ConfigureLogging((hostingContext, logging) =>
{
logging.AddEventLog();
logging.SetMinimumLevel(_logLevel);
})
.ConfigureServices((hostContext, services) =>
{
services.AddSingleton<IHostLifetime, WindowsServiceLifetime>();
services.Configure<EventLogSettings>(settings =>
{
if (string.IsNullOrEmpty(settings.SourceName))
{
settings.SourceName = hostContext.HostingEnvironment.ApplicationName;
}
});
});
}
hostBuilder.Build().Run();
}
}