From 300da63a80f39609c94f7ef4c22683bffd3e866b Mon Sep 17 00:00:00 2001 From: timfeirg Date: Sat, 15 Apr 2017 15:43:12 +0800 Subject: [PATCH] implement graceful stop using GracefulStop --- VERSION | 2 +- main.go | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/VERSION b/VERSION index bb3af194b..cb80b803c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.7.28a +0.7.29 diff --git a/main.go b/main.go index 9fb0a3759..98c51359f 100644 --- a/main.go +++ b/main.go @@ -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 { @@ -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() {