Skip to content

Commit 9ad986f

Browse files
Reusing the existing fucntion to implement graceful shutdown logic (#33)
1 parent f4adff9 commit 9ad986f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

share/cos/common.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"os"
66
"os/signal"
77
"time"
8+
"syscall"
9+
"log"
810
)
911

1012
//InterruptContext returns a context which is
@@ -13,9 +15,11 @@ func InterruptContext() context.Context {
1315
ctx, cancel := context.WithCancel(context.Background())
1416
go func() {
1517
sig := make(chan os.Signal, 1)
16-
signal.Notify(sig, os.Interrupt) //windows compatible?
17-
<-sig
18+
signal.Notify(sig, os.Interrupt, syscall.SIGTERM) //windows compatible?
19+
s := <-sig
20+
log.Printf("Graceful shutdown signal received: %s", s)
1821
signal.Stop(sig)
22+
log.Println("Graceful shutdown complete.")
1923
cancel()
2024
}()
2125
return ctx

0 commit comments

Comments
 (0)