Stop a running dotnet core website running on kestrel
I have decided to use supervisor to monitor and manage the process. Here is an excellent article on getting it set up.
It allows simple control over specific dotnet apps like this:
supervisorctl stop MyWebsiteName
supervisorctl start MyWebsiteName
And it has one huge advantage in that it can try restart the process if it falls over, or when the system reboots... for whatever reason.
Stop Kestrel server accepting requests from code
During the lifetime of the application I want to be able to Pause/Stop the endpoint/Server from listening/accepting requests and after a while resuming it.
This isn't possible today but will be in 5.0. I'd suggest commenting on this issue https://github.com/dotnet/aspnetcore/issues/21244
How to quit ASP.NET Kestrel web server on a Mac
It turns out that simply hitting "Enter" exits kestrel cleanly, without the need to kill the mono-sgen process afterward. There is a github issue on the Kestrel repo asking to make this more obvious.
Can I keep an ASP.NET Core web site running after stopping debugging?
Edit the properties for the web site project (right-click in Solution Explorer and select Properties) and then select the Debug tab on the right.
Under Web Server Settings, change Hosting Model to Out of Process.
Now, when debugging is stopped the website should continue to run in IIS Express.
Notes:
- Tested in Visual Studio 2017 and Visual Studio 2019
- The default hosting model for VS2017 is "In Process", in case you're wondering.
- It does not appear to make a difference whether or not you have 'Enable Edit and Continue' selected in Tools > Options > Debugging.
How to stop a self hosted Kestrel application?
Found the most obvious way to cancel Kestrel. Run has an overload accepting a cancellation Token.
public static class WebHostExtensions
{
/// <summary>
/// Runs a web application and block the calling thread until host shutdown.
/// </summary>
/// <param name="host">The <see cref="T:Microsoft.AspNetCore.Hosting.IWebHost" /> to run.</param>
public static void Run(this IWebHost host);
/// <summary>
/// Runs a web application and block the calling thread until token is triggered or shutdown is triggered.
/// </summary>
/// <param name="host">The <see cref="T:Microsoft.AspNetCore.Hosting.IWebHost" /> to run.</param>
/// <param name="token">The token to trigger shutdown.</param>
public static void RunAsync(this IWebHost host, CancellationToken token);
}
So passing the cancellation token to
host.Run(ct);
solves it.
How to make Kestrel console window auto close/reset upon each rebuild in Visual Studio ASP.NET Core web projects?
You mean this?
Tools → Options → Debugging → General → Automatically close the console when debugging stops
Related Topics
Recording from Alsa - Understanding Memory Mapping
Change Conda Default Pkgs_Dirs and Envs Dirs
Shipping Gnu/Linux Firefox Plugin with Shared Libraries (For Installation with No Root Access)
How to Launch a Job in a Shell Which Will Persist Even If The Shell Which Launches It Terminates
Is There an Os Command I Can Run to Determine If Running Inside a Xen Based Virtual Machine
How to Test My Bash Script on Older Versions of Bash
Amazon Linux Ami Ec2 Gui/Remote Desktop
Is Visual Basic Supported by .Net Core on Linux
Create Infinite Looping Repeating File Cat in Linux/Bash
Read Lines Between Two Keywords
Using Git to Clone from a Windows Machine to a Linux Webserver (In House)
In Bash, How to Expand Variables Twice in Double Quotes
Linux/Unix Socket Self-Connection
Install Sqlite3 Dev and Other Packages in Centos
How to Stop Sed from Buffering
Use Grep to Remove Words from Dictionary Whose Roots Are Already Present