I need to notify systemd
that my service has started up successfully, and a task it needs to run after startup requires that the server is already listening on the target Unix domain socket.
I am using IWebHost::Run
to start the server, and that is a blocking call. Additionally, I am unable to find any obvious way to set a delegate or callback event for successful initialization.
Anyone?
This is what I ended up going with, for now. Seems to be working fine:
Then, in the Ctrl+C event handler:
On
.Net Core 1.x
it is safe to just runIWebHost.Start()
and assume that the server is initialized afterwards (instead ofRun()
that blocks the thread). Check the source.If you are using
.NET Core 2.0 Preview 1
(or later), the source is different, the synchronous method is not available anymore so you should awaitIWebHost.StartAsync()
and assume everything is ready afterwards.You may use Microsoft.AspNetCore.Hosting.IApplicationLifetime:
Look into this SO post for the configuration example.