Maint: better log when cathing an OS signal

This commit is contained in:
Quentin McGaw (desktop)
2021-08-18 21:22:27 +00:00
parent 0027a76c49
commit 538bc72c3c

View File

@@ -59,9 +59,9 @@ func main() {
Created: created, Created: created,
} }
ctx := context.Background() background := context.Background()
ctx, stop := signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM, os.Interrupt) signalCtx, stop := signal.NotifyContext(background, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
ctx, cancel := context.WithCancel(ctx) ctx, cancel := context.WithCancel(background)
logger := logging.NewParent(logging.Settings{ logger := logging.NewParent(logging.Settings{
Level: logging.LevelInfo, Level: logging.LevelInfo,
@@ -79,9 +79,11 @@ func main() {
}() }()
select { select {
case <-ctx.Done(): case <-signalCtx.Done():
stop() stop()
fmt.Println("")
logger.Warn("Caught OS signal, shutting down") logger.Warn("Caught OS signal, shutting down")
cancel()
case err := <-errorCh: case err := <-errorCh:
stop() stop()
close(errorCh) close(errorCh)