Skip to content

Commit

Permalink
Graceful shutdown - agent
Browse files Browse the repository at this point in the history
  • Loading branch information
Pankaj Kumar committed Feb 16, 2022
1 parent a21e633 commit 66d97e9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
32 changes: 26 additions & 6 deletions endpoint/cli/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand All @@ -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")

}
2 changes: 1 addition & 1 deletion endpoint/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down

0 comments on commit 66d97e9

Please sign in to comment.