Skip to content

Sample .NET Core application that can respond to SIGTERM

Notifications You must be signed in to change notification settings

richardcase/netcoresigterm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

.NET Core & SIGTERM

A demo .NET Core application for running on Linux that shows how to workaround .NET Cores support for SIGTERM.

Background

Docker uses SIGTERM to signal to a process running in a container that it intends to stop teh container. This gives the process time to gracefully shutdown before the container is stopped and the process is forcibully shutdown (with SIGTERM).

This is essential for Kubernetes as this is how you can update a web service / UI using a rolling upgrade with zero downtime. Kubernetes/Docker will SIGTERM the container at which point the hosted service should return failure for the health probe. This will ensure that no new work is sent to the instance. See: https://pracucci.com/graceful-shutdown-of-kubernetes-pods.html

To deploy

  1. Clone the repo
  2. Edit sigtermtest to ensure the dir parameter points to the clone folder
  3. Copy sigtermtest to /etc/init.d/
  4. Make sigtermtest executable (i.e. chmod +x sigtermtest)
  5. As root run:
/etc/init.d/sigtermtest start
  1. View the log output of the application by running:
tail -f /var/log/sigtermtest.log
  1. Kill the dotnet process using kill

You should see the process is signalled and continues to process for 10 seconds.

The init script is based on a template from: https://github.com/fhd/init-script-template

About

Sample .NET Core application that can respond to SIGTERM

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published