Skip to content

Commit

Permalink
Shutdown gracefully if the terminal was closed(sighup)
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-ssvlabs committed Aug 29, 2024
1 parent 0b17972 commit 3d20f2a
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions internal/platform/lifecycle/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ import (
const terminationDelay = time.Second * 5

func ListenForApplicationShutDown(ctx context.Context, shutdownFunc func(), signalChannel chan os.Signal) {
signal.Notify(signalChannel, os.Interrupt, syscall.SIGTERM)
signal.Notify(signalChannel, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGINT)

select {
case sig := <-signalChannel:
switch sig {
case os.Interrupt, syscall.SIGTERM:
slog.Warn("shutdown signal received")
shutdownFunc()
time.Sleep(terminationDelay)
}
slog.With("sig", sig.String()).Warn("shutdown signal received")
shutdownFunc()
time.Sleep(terminationDelay)
case <-ctx.Done():
slog.Warn("context deadline exceeded or canceled")
shutdownFunc()
Expand Down

0 comments on commit 3d20f2a

Please sign in to comment.