c# - linux下的topshelf和.net core
问题描述
我有一个简单的应用程序,它使用 topshelf 作为服务启动,它看起来很简单:
HostFactory.Run(x =>
{
x.Service<RequestService>();
x.RunAsLocalSystem();
});
好吧,它可以工作,但是在Windows下。当我在 Linux 下尝试这个时,我得到:
Topshelf.Runtime.Windows.WindowsHostEnvironment 错误:0:无法获取父进程(忽略),System.DllNotFoundException:无法加载共享库“kernel32.dll”或其依赖项之一。为了帮助诊断加载问题,请考虑设置 LD_DEBUG 环境变量: libkernel32.dll:无法打开共享对象文件:没有这样的文件或目录
有人遇到过这个问题吗?我试图用谷歌搜索它,但有人说它可以工作,因为它只是用于 Windows 的工具。
或者,.net 核心可能还有其他一些服务提升框架?
解决方案
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>();
});
推荐阅读
- java - 表单中的 ModelAttribute 无法与对象绑定(Spring MVC)
- ios - 如何实现顶部带有标题的水平滚动集合视图?
- apache-spark - Pyspark - 计算新项目的长度
- javascript - 如何防止 VueJs 在 DOM 完全挂载之前更新数据
- spring-boot - Kubernetes 部署成功,但没有显示更新的内容
- apache-spark - 当底层文件发生变化时,PySpark 应该刷新视图还是源表?
- python - 在 Python Docker API 中实现“docker rmi”
- java - 如何为许多作者和许多读者(线程)添加和删除 HashMap?
- windows-subsystem-for-linux - WSL(Linux 的 Windows 子系统)中的 fsck(文件系统检查)
- android - 将吐司放在顶部