runtime: Microsoft.Extensions.Hosting.Systemd.SystemdHelpers.IsSystemdService does not work inside containers.
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
Microsoft.Extensions.Hosting.UseSystemd() is set up to no-op if IsSystemdService() returns false. However, IsSystemdService() only returns true if the direct parent process is systemd. This is not true when we have a container runtime (e.g. podman) acting as a middleman, and thus containerised systemd services do not have sd-notify integration or systemd log formatting.
Expected Behavior
If there exists a more robust check that would work in containerised deployments, then IsSystemdService() should use that.
Otherwise, an overload of UseSystemd() should be created (e.g. UseSystemd(bool forceEnable = false)) that allows users to forcibly enable sd-notify integration and systemd log formatting, without having to manually copy the part of UseSystemd() that is inside the if statement from the reference source into our startup code, since this code may be subject to change in the future.
Steps To Reproduce
Minimalist reproduction here
Exceptions (if any)
No response
.NET Version
6.0.101
Anything else?
.NET SDK (reflecting any global.json):
Version: 6.0.101
Commit: ef49f6213a
Runtime Environment:
OS Name: fedora
OS Version: 35
OS Platform: Linux
RID: fedora.35-x64
Base Path: /home/james/.dotnet/sdk/6.0.101/
Host (useful for support):
Version: 6.0.1
Commit: 3a25a7f1cc
.NET SDKs installed:
6.0.101 [/home/james/.dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.1 [/home/james/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.1 [/home/james/.dotnet/shared/Microsoft.NETCore.App]
To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (14 by maintainers)
Commits related to this issue
- Detect systemd when inside a container. Modify IsSystemdService to function correctly for containerised services. Fix #67203 Signed-off-by: james <judilsteve> — committed to judilsteve/runtime by deleted user 2 years ago
- Detect systemd when inside a container. (#67288) * Detect systemd when inside a container. Modify IsSystemdService to function correctly for containerised services. Fix #67203 Adds conditio... — committed to dotnet/runtime by judilsteve 2 years ago
@tmds I’ll see if I can take a run at it tomorrow after work, but I haven’t contributed to dotnet before, so I might need some guidance as to the project’s style/conventions in the resulting PR.