Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop a running dotnet core website running on kestrel

When deploying a new version of an existing .net core website. How do I first safely stop the old running kestrel app?

Here is an exmaple of what I would like to write (Pseudo deployment script):

dotnet stop mysite/mysite.dll <---- this line here
mv mysite/ mysite.bak/
cp newly-published-mysite/ mysite/
dotnet run mysite/mysite.dll

killall dotnet seems a little unsafe. How would it work if I were hosting two small sites on one box?

like image 240
Craigt Avatar asked Apr 09 '17 11:04

Craigt


People also ask

How do you stop a Kestrel server in Linux?

run netstat -ano -p TCP | find /I "listening" | find /I "port number" then run taskkill /F /PID process ID on Command Prompt. C:\Users\Kiran>netstat -ano -p TCP | find /I "listening" | find /I "2492" TCP 127.0. 0.1:2492 0.0.

How do you reset a Kestrel server?

Kestrel is not a stand-alone web server unlike Nginx, Apache or IIS. Therefore it cannot exists without the dotnet process and cannot be restarted itself. You should restart the underlying systemd service you setup to run your web application.

What is Kestrel server in .NET core?

Kestrel is a cross-platform web server for ASP.NET Core. Kestrel is the web server that's included by default in ASP.NET Core project templates. Kestrel supports the following scenarios: HTTPS. Opaque upgrade used to enable WebSockets.


2 Answers

Accordingly to this discussion, there is no safe way to stop Kestrel now. You need to find a PID by name of your dll and kill it:

kill $(ps aux | grep 'MySite.dll' | awk '{print $2}')

In case of process tree, you need to manually grep all child IDs and call kill for each. Like it was done in Microsoft.Extensions.Internal.ProcessExtensions.KillTree method (correct link from the discussion).

like image 154
Ilya Chumakov Avatar answered Sep 18 '22 20:09

Ilya Chumakov


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.

like image 33
Craigt Avatar answered Sep 17 '22 20:09

Craigt