.NET 5/6 - What does UseSystemd() actually do?
Asked Answered
S

1

7

I have a .NET API with a few Worker Services that I deploy on a CentOS 8 server. I know that there is a function in Microsoft.Extensions.Hosting package that is called UseSystemd(), which is supposed to help it run on Systemd. I can't figure out what it actually does or enables.

I have upgraded my .NET 5 api to .NET 6 and I cannot figure out where to put it, so I didn't add it. I did not have it in my .NET 5 api and it worked fine.

My package deploys and I run it with a Systemd service (without the Systemd()) and it runs just fine. It detects crashes like normal and I can view logs with journalctl

So, It doesn't seem like I need it. What does it actually do?

Selfdefense answered 2/6, 2022 at 16:46 Comment(1)
I think here is the answer - swimburger.net/blog/dotnet/…Mule
B
0

Ankush already provided a helpful link in the comments.

To summarize:

Microsoft recently added a package to better integrate with systemd. When the integration is installed, the application will notify systemd when it's ready and when it's stopping. Additionally, systemd will understand the different log levels that the application logs.

For this to work, you need to configure the service as "Type=notify" in the .service file.

[Service]
Type=notify

From https://askubuntu.com/a/1120288/1494411

If you set up a service using Type=notify, systemd will automatically set up a communication socket back to systemd and will export its path to the service under $NOTIFY_SOCKET.
It will also listen for special messages in that socket, such as whether the service is ready (in which case systemd will transition it to status started, since initialization is completed) and also the self-reported status of the service, which will also be reported in the output of systemctl status mytest.service (assuming a service called mytest.)

Broil answered 21/2 at 8:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.