diff --git a/README.md b/README.md index fc8564e72b7f1ac2e715586867d19f59975e264e..2551aeda59f075276637883e18448330a80a65e6 100644 --- a/README.md +++ b/README.md @@ -17,3 +17,4 @@ This means that a central `QKDN-Controller` is responsible to manage and configu - [Logging Guide](docs/Logging.md) - [Tracing Guide](docs/Tracing.md) - [Definition of Done](docs/dod.md) +- [Graceful Shutdown](docs/graceful-shutdown.md) diff --git a/docs/graceful-shutdown.md b/docs/graceful-shutdown.md new file mode 100644 index 0000000000000000000000000000000000000000..c69e05f08b798fbf53667f628553ef98c27b4c0b --- /dev/null +++ b/docs/graceful-shutdown.md @@ -0,0 +1,32 @@ +# Graceful Shutdown + +We use the `io.Closer` interface to implement graceful shutdown in our services. +This allows us to close any open resources, such as database connections or +network listeners, before the service exits. + +## Example + +```go +# main.go + +... +shutdown.AddShutdownHook(logs, grpcServer, ...) +``` + +The shutdown hook makes sure to close the `Close()` method of everything +that implements the `io.Closer` interface. +Therefore each service can implement its own `Close()` method and handle +the shutdown process in a way that makes sense for that service. + +The following is an example for our gRPC server implementation: + +```go +type gRPCServer struct{ +} + +func (g gRPCServer) Close() error { + g.grpcServer.GracefulStop() + + return nil +} +```