A demo .NET Core application for running on Linux that shows how to workaround .NET Cores support for SIGTERM.
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
- Clone the repo
- Edit sigtermtest to ensure the dir parameter points to the clone folder
- Copy sigtermtest to /etc/init.d/
- Make sigtermtest executable (i.e. chmod +x sigtermtest)
- As root run:
/etc/init.d/sigtermtest start
- View the log output of the application by running:
tail -f /var/log/sigtermtest.log
- 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