Skip to content

Commit

Permalink
implement graceful stop using GracefulStop
Browse files Browse the repository at this point in the history
  • Loading branch information
timfeirg committed Apr 15, 2017
1 parent 7701415 commit 300da63
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7.28a
0.7.29
15 changes: 7 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ var (
logLevel string
)

func waitSignal() {
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGHUP, syscall.SIGKILL, syscall.SIGTERM, syscall.SIGQUIT)
<-c
log.Info("Terminating...")
}

func setupLog(l string) error {
level, err := log.ParseLevel(l)
if err != nil {
Expand Down Expand Up @@ -106,7 +99,13 @@ func serve() {
go http.ListenAndServe(":46656", nil)

log.Info("Cluster started successfully.")
waitSignal()

// wait for unix signals and try to GracefulStop
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGHUP, syscall.SIGTERM)
<-sigs
grpcServer.GracefulStop()
log.Info("Terminating...")
}

func main() {
Expand Down

0 comments on commit 300da63

Please sign in to comment.