Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consume PosixSignal in Microsoft.Extensions.Hosting.Systemd's SystemdLifetime #56058

Closed
eerhardt opened this issue Jul 20, 2021 · 2 comments · Fixed by #59880
Closed

Consume PosixSignal in Microsoft.Extensions.Hosting.Systemd's SystemdLifetime #56058

eerhardt opened this issue Jul 20, 2021 · 2 comments · Fixed by #59880

Comments

@eerhardt
Copy link
Member

Same change as #55417, but we should make it for Systemd.

// systemd sends SIGTERM to stop the service.
AppDomain.CurrentDomain.ProcessExit += OnProcessExit;
return Task.CompletedTask;
}
private void OnApplicationStarted()
{
Logger.LogInformation("Application started. Hosting environment: {EnvironmentName}; Content root path: {ContentRoot}",
Environment.EnvironmentName, Environment.ContentRootPath);
SystemdNotifier.Notify(ServiceState.Ready);
}
private void OnApplicationStopping()
{
Logger.LogInformation("Application is shutting down...");
SystemdNotifier.Notify(ServiceState.Stopping);
}
private void OnProcessExit(object sender, EventArgs e)
{
ApplicationLifetime.StopApplication();
_shutdownBlock.WaitOne();
// On Linux if the shutdown is triggered by SIGTERM then that's signaled with the 143 exit code.
// Suppress that since we shut down gracefully. https://github.com/dotnet/aspnetcore/issues/6526
System.Environment.ExitCode = 0;
}

We should also figure out how to add real tests, as I don't believe there are any tests for this library, yet. The only test we have:

public void DefaultsToOffOutsideOfService()
{
var host = new HostBuilder()
.UseSystemd()
.Build();
using (host)
{
var lifetime = host.Services.GetRequiredService<IHostLifetime>();
Assert.IsType<ConsoleLifetime>(lifetime);
}
}

tests that Systemd is "off" when not in a systemd service.

@dotnet-issue-labeler dotnet-issue-labeler bot added area-Infrastructure-libraries untriaged New issue has not been triaged by the area owner labels Jul 20, 2021
@ghost
Copy link

ghost commented Jul 20, 2021

Tagging subscribers to this area: @Anipik, @safern, @ViktorHofer
See info in area-owners.md if you want to be subscribed.

Issue Details

Same change as #55417, but we should make it for Systemd.

// systemd sends SIGTERM to stop the service.
AppDomain.CurrentDomain.ProcessExit += OnProcessExit;
return Task.CompletedTask;
}
private void OnApplicationStarted()
{
Logger.LogInformation("Application started. Hosting environment: {EnvironmentName}; Content root path: {ContentRoot}",
Environment.EnvironmentName, Environment.ContentRootPath);
SystemdNotifier.Notify(ServiceState.Ready);
}
private void OnApplicationStopping()
{
Logger.LogInformation("Application is shutting down...");
SystemdNotifier.Notify(ServiceState.Stopping);
}
private void OnProcessExit(object sender, EventArgs e)
{
ApplicationLifetime.StopApplication();
_shutdownBlock.WaitOne();
// On Linux if the shutdown is triggered by SIGTERM then that's signaled with the 143 exit code.
// Suppress that since we shut down gracefully. https://github.com/dotnet/aspnetcore/issues/6526
System.Environment.ExitCode = 0;
}

We should also figure out how to add real tests, as I don't believe there are any tests for this library, yet. The only test we have:

public void DefaultsToOffOutsideOfService()
{
var host = new HostBuilder()
.UseSystemd()
.Build();
using (host)
{
var lifetime = host.Services.GetRequiredService<IHostLifetime>();
Assert.IsType<ConsoleLifetime>(lifetime);
}
}

tests that Systemd is "off" when not in a systemd service.

Author: eerhardt
Assignees: -
Labels:

area-Infrastructure-libraries, untriaged

Milestone: -

@eerhardt
Copy link
Member Author

cc @tmds

@maryamariyan maryamariyan removed the untriaged New issue has not been triaged by the area owner label Jul 22, 2021
@maryamariyan maryamariyan added this to the 7.0.0 milestone Jul 22, 2021
eerhardt added a commit to eerhardt/runtime that referenced this issue Oct 1, 2021
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Oct 1, 2021
eerhardt added a commit that referenced this issue Nov 1, 2021
* Consume PosixSignal in Hosting.Systemd's SystemdLifetime

Fix #56058

* Fix TFMs to correctly include NetCoreApp

Also fixing duplicate entries in the .sln file, since it doesn't load correctly.
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Nov 1, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Dec 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants