I could just write a long-running CLI app and run it, but I'm assuming it wouldn't comply to all the expectations one would have of a standards-compliant linux daemon (responding to SIGTERM, Started by System V init process, Ignore terminal I/O signals, etc.)
Most ecosystems have some best-practice way of doing this, for example, in python, you can use https://pypi.python.org/pypi/python-daemon/
Is there some documentation about how to do this with .Net Core?
If you're trying to find something more robust, I found an implementation on Github that looks promising: .NET Core Application blocks for message-based communication. It uses
Host
,HostBuilder
,ApplicationServices
,ApplicationEnvironment
, etc classes to implement a messaging service.It doesn't quite look ready for black box reuse, but it seems like it could be a good starting point.
I toyed with an idea similar to how .net core web host waits for shutdown in console applications. I was reviewing it on GitHub and was able to extract the gist of how they performed the
Run
https://github.com/aspnet/Hosting/blob/15008b0b7fcb54235a9de3ab844c066aaf42ea44/src/Microsoft.AspNetCore.Hosting/WebHostExtensions.cs#L86
I tried adapting something like a
IConsoleHost
but quickly realized I was over-engineering it. Extracted the main parts into something likeawait ConsoleUtil.WaitForShutdownAsync();
that operated likeConsole.ReadLine
This then allowed the utility to be used like this
from there creating a systemd as in the following link should get you the rest of the way
Writing a Linux daemon in C#
The best I could come up with is based on the answer to two other questions: Killing gracefully a .NET Core daemon running on Linux and Is it possible to await an event instead of another async method?
Have you tried Thread.Sleep (Timeout.Infinite) ?