C# 如何使用单声道将 .NET Windows 服务应用程序迁移到 Linux?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/637948/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 11:17:49  来源:igfitidea点击:

How to migrate a .NET Windows Service application to Linux using mono?

c#.netlinux.net-2.0mono

提问by Raúl Roa

What would be the best approach to migrate a .NET Windows Service to Linux using mono? I've been trying to avoid executing the application as a scheduled command.

使用单声道将 .NET Windows 服务迁移到 Linux 的最佳方法是什么?我一直试图避免将应用程序作为预定命令执行。

Is it possible to obtain a service/system daemon(in linux) like behavior?

是否可以获得类似行为的服务/系统守护进程(在 linux 中)?

采纳答案by gimel

Under Linux, deamonsare simple background processes. No special control methods (e.g start(), stop()) are used as in Windows. Build your service as a simple (console) application, and run it in the background. Use a tool like daemonizeto run a program as a Unix daemon, and remember to specify monoas the program to be activated.

在 Linux 下,守护进程是简单的后台进程。没有像在 Windows 中那样使用特殊的控制方法(例如start(), stop())。将您的服务构建为一个简单的(控制台)应用程序,并在后台运行它。使用类似daemonizeUnix守护进程运行程序的工具,记得指定mono为要激活的程序。

As noted by others, mono-serviceis a host to run services built with the ServiceProcessassembly. Services built for Windows can use this method to run unmodified under Linux. You can control the service by sending signals to the process (see man page).

正如其他人所指出的,单服务是运行用ServiceProcess程序集构建的服务的主机。为 Windows 构建的服务可以使用此方法在 Linux 下未经修改地运行。您可以通过向进程发送信号来控制服务(参见手册页)。

回答by Marc Gravell

Can you use mono-service to wrap it?

你能用mono-service来包装它吗?

See this question.

看到这个问题

回答by sipwiz

The way I have done it in the past is to compile the .Net application as a console application and then on the Linux server create a startup script in the initscripts directory.

我过去的做法是将 .Net 应用程序编译为控制台应用程序,然后在 Linux 服务器上的 initscripts 目录中创建一个启动脚本。

Linux obviously does not have Windows services and the daemons that are initiated from the rc.d directories on startup are its equivalent. All most of the rc.d scripts do is start the different applications on a background thread so there's nothing really complicated to it. The only bit of extra work is that you will need to write a Linux shell script to start and if you want stop the service.

Linux 显然没有 Windows 服务,并且在启动时从 rc.d 目录启动的守护进程是等效的。大多数 rc.d 脚本所做的就是在后台线程上启动不同的应用程序,因此没有什么真正复杂的。唯一的额外工作是您需要编写一个 Linux shell 脚本来启动和停止服务。