diff --git a/endpoint/cli/agent/main.go b/endpoint/cli/agent/main.go index 01faae8..6564d63 100644 --- a/endpoint/cli/agent/main.go +++ b/endpoint/cli/agent/main.go @@ -5,6 +5,9 @@ import ( "fmt" "log" "net" + "os" + "os/signal" + "syscall" "github.com/pnkj-kmr/infra-patch-manager/agent" "github.com/pnkj-kmr/infra-patch-manager/entity" @@ -20,9 +23,9 @@ func main() { flag.Parse() log.Printf("server start on port : %d", *port) - pingServer := agent.NewPatchServer() + patch := agent.NewPatchServer() grpcServer := grpc.NewServer() - pb.RegisterPatchServer(grpcServer, pingServer) + pb.RegisterPatchServer(grpcServer, patch) // // TO DEBUG THE gRPC SERVICE with help to // // EVANS Client --- https://github.com/ktr0731/evans // reflection.Register(grpcServer) @@ -33,8 +36,25 @@ func main() { log.Fatal("cannot start the server agent ", err) } - err = grpcServer.Serve(listener) - if err != nil { - log.Fatal("cannot start the grpc server agent ", err) - } + // err = grpcServer.Serve(listener) + // if err != nil { + // log.Fatal("cannot start the grpc server agent ", err) + // } + + // Graceful shutdwon of server + done := make(chan os.Signal, 1) + signal.Notify(done, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) + + go func() { + if err = grpcServer.Serve(listener); err != nil { + log.Fatalf("listen: %s\n", err) + done <- syscall.SIGTERM + } + }() + log.Print("server started") + + <-done + grpcServer.GracefulStop() + log.Print("server exited properly") + } diff --git a/endpoint/cli/cli.go b/endpoint/cli/cli.go index c07918f..97daf77 100644 --- a/endpoint/cli/cli.go +++ b/endpoint/cli/cli.go @@ -84,7 +84,7 @@ func DefaultHelp() { fmt.Println(greenText(" extract"), " | untaring a tar.gz file on relative remote") fmt.Println(greenText(" apply"), " | applying a patch to relative remote application(s)") fmt.Println(greenText(" verify"), " | helps to validate an applied patch") - fmt.Println(greenText(" exec"), " | Helps to execute cmd on remote(s)") + fmt.Println(greenText(" exec"), " | helps to execute commands on remote(s)") fmt.Print("\n\n") }