feat: graceful shutdown on SIGINT and SIGTERM (#649)

A second SIGINT forces shutdown, as usual.
This commit is contained in:
Kevin Lindsay
2023-05-26 12:18:40 +00:00
committed by GitHub
parent 8402f73d52
commit e2e06a8f83

View File

@@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"os" "os"
"os/signal" "os/signal"
"syscall"
"time" "time"
"github.com/gotenberg/gotenberg/v7/pkg/gotenberg" "github.com/gotenberg/gotenberg/v7/pkg/gotenberg"
@@ -109,8 +110,8 @@ func Run() {
quit := make(chan os.Signal, 1) quit := make(chan os.Signal, 1)
// We'll accept graceful shutdowns when quit via SIGINT (Ctrl+C). // We'll accept graceful shutdowns when quit via SIGINT (Ctrl+C) or SIGTERM (Kubernetes).
signal.Notify(quit, os.Interrupt) signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
// Block until we receive our signal. // Block until we receive our signal.
<-quit <-quit
@@ -119,7 +120,7 @@ func Run() {
defer cancel() defer cancel()
forceQuit := make(chan os.Signal, 1) forceQuit := make(chan os.Signal, 1)
signal.Notify(forceQuit, os.Interrupt) signal.Notify(forceQuit, syscall.SIGINT)
go func() { go func() {
// In case of force quit, cancel the context. // In case of force quit, cancel the context.