Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
chore: log OS signal on exit in HTTP mode
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz committed Jun 25, 2024
1 parent c9d64a5 commit 5a7d002
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions cmd/http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ import (

func main() {
log.Info("NWC Starting in HTTP mode")
ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM, os.Kill)

// Create a channel to receive OS signals.
osSignalChannel := make(chan os.Signal, 1)
// Notify the channel on os.Interrupt, syscall.SIGTERM, and os.Kill.
signal.Notify(osSignalChannel, os.Interrupt, syscall.SIGTERM, os.Kill)

ctx, cancel := context.WithCancel(context.Background())
svc, _ := service.NewService(ctx)

echologrus.Logger = logger.Logger
Expand All @@ -34,10 +40,16 @@ func main() {
logger.Logger.Fatalf("shutting down the server: %v", err)
}
}()

// wait for exit signal
signal := <-osSignalChannel
logger.Logger.WithField("signal", signal).Info("Received OS signal")
cancel()

//handle graceful shutdown
<-ctx.Done()
logger.Logger.Infof("Shutting down echo server...")
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
logger.Logger.Info("Shutting down echo server...")
ctx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
e.Shutdown(ctx)
logger.Logger.Info("Echo server exited")
Expand Down

0 comments on commit 5a7d002

Please sign in to comment.