[英]Topshelf and .net core under linux
我有一個簡單的應用程序,它使用 topshelf 作為服務啟動,它看起來很簡單:
HostFactory.Run(x =>
{
x.Service<RequestService>();
x.RunAsLocalSystem();
});
好吧,它有效,但在 windows 下。 當我在 Linux 下嘗試這個時,我得到:
Topshelf.Runtime.Windows.WindowsHostEnvironment 錯誤:0:無法獲取父進程(被忽略),System.DllNotFoundException:無法加載共享庫“kernel32.dll”或其依賴項之一。 為了幫助診斷加載問題,請考慮設置 LD_DEBUG 環境變量:libkernel32.dll: cannot open shared object file: No such file or directory
有人遇到過這個問題嗎? 我試圖用谷歌搜索它,但有人說它可以工作,因為它是僅適用於 Windows 的工具。
或者也許還有其他一些適用於 .net core 的服務提升框架?
假設您安裝了此版本的 Topshelf - 您會在依賴項下注意到它不支持 .NET Core,因此它不會在 Linux 環境下運行。
正如您在帖子中提到的,它只能在 Windows 環境下運行。 kernel32.dll
是它無法找到的 Windows 依賴項,因此無法運行。
Topshelf 不是跨平台的,因此它不支持非 Windows 環境中的 .Net Core,即使它可以在它們中運行(至少在撰寫本文時)。
解決方案是更改環境構建器。 這是我的項目中的一個示例,在創建服務時:
HostFactory.Run(c =>
{
// Change Topshelf's environment builder on non-Windows hosts:
if (
RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ||
RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
)
{
c.UseEnvironmentBuilder(
target => new DotNetCoreEnvironmentBuilder(target)
);
}
c.SetServiceName("SelloutReportingService");
c.SetDisplayName("Sellout Reporting Service");
c.SetDescription(
"A reporting service that does something...");
c.StartAutomatically();
c.RunAsNetworkService();
c.EnableServiceRecovery(
a => a.RestartService(TimeSpan.FromSeconds(60))
);
c.StartAutomatically();
c.Service<SelloutReportingService>();
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.