是否可以使用相同的代码创建一个可以作为 Windows 服务和 Linux 上的守护程序运行的 .NET Core 应用程序?
您有示例/概念证明吗?
请您参考如下方法:
Linux 守护程序服务可以采用任何可以在系统上执行的语言。
可以使用 systemd 执行守护进程(在 Fedora 中:systemctl start name.service)。要将您的程序放在 Linux Systemd 服务上,您应该创建一个新的 .service 文件并将其移至“/etc/systemd/system/”
服务的语法是:
[Unit]
Description=The description of your service
After=previous services needed
[Service]
ExecStart=The program execution /sbin/helloworld.exe
ExecStop=The command given when killing the service
[Install]
WantedBy=services that needs your service
有关 Linux-Red Hat 服务和服务模块的更多信息:https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/sect-Managing_Services_with_systemd-Unit_Files.html