Skip to content

Commit

Permalink
graceful shutdown on SIGTERM,SIGQUIT,SIGINT
Browse files Browse the repository at this point in the history
  • Loading branch information
The-Gleb committed Mar 17, 2024
1 parent 6f46514 commit cc034cc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"runtime"
"sync"
"sync/atomic"
"syscall"
"time"

"github.com/shirou/gopsutil/v3/cpu"
Expand Down Expand Up @@ -63,7 +64,7 @@ func main() {
var reportInterval = time.Duration(config.ReportInterval * 1000000000)

c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)

pollTicker := time.NewTicker(pollInterval)
reportTicker := time.NewTicker(reportInterval)
Expand Down
2 changes: 1 addition & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func main() {
}

func Run(ctx context.Context) error {
ctx, cancel := signal.NotifyContext(ctx, syscall.SIGINT)
ctx, cancel := signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
defer cancel()

go func() {
Expand Down

0 comments on commit cc034cc

Please sign in to comment.