feat(shutdown): log out OS signal name
This commit is contained in:
@@ -64,7 +64,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
background := context.Background()
|
background := context.Background()
|
||||||
signalCtx, stop := signal.NotifyContext(background, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
|
signalCh := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM)
|
||||||
ctx, cancel := context.WithCancel(background)
|
ctx, cancel := context.WithCancel(background)
|
||||||
|
|
||||||
logger := logging.New(logging.Settings{
|
logger := logging.New(logging.Settings{
|
||||||
@@ -88,13 +89,11 @@ func main() {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-signalCtx.Done():
|
case signal := <-signalCh:
|
||||||
stop()
|
|
||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
logger.Warn("Caught OS signal, shutting down")
|
logger.Warn("Caught OS signal " + signal.String() + ", shutting down")
|
||||||
cancel()
|
cancel()
|
||||||
case err := <-errorCh:
|
case err := <-errorCh:
|
||||||
stop()
|
|
||||||
close(errorCh)
|
close(errorCh)
|
||||||
if err == nil { // expected exit such as healthcheck
|
if err == nil { // expected exit such as healthcheck
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
@@ -113,6 +112,8 @@ func main() {
|
|||||||
logger.Info("Shutdown successful")
|
logger.Info("Shutdown successful")
|
||||||
case <-timer.C:
|
case <-timer.C:
|
||||||
logger.Warn("Shutdown timed out")
|
logger.Warn("Shutdown timed out")
|
||||||
|
case signal := <-signalCh:
|
||||||
|
logger.Warn("Caught OS signal " + signal.String() + ", forcing shut down")
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user