gracegrpc is used to wrap a grpc server that can be gracefully terminated & restarted.
go get github.com/0x5010/gracegrpc
Wrap grpc server and start server:
s := grpc.NewServer()
pb.RegisterDeployServer(s, &server{})
reflection.Register(s)
gr, err := gracegrpc.New(s, "tcp", addr, pidPath, nil)
if err != nil {
log.Fatalf("failed to new gracegrpc: %v", err)
}
if err := gr.Serve(); err != nil {
log.Fatalf("failed to serve: %v", err)
}
Custom logger
import log "github.com/sirupsen/logrus"
...
gr, err := gracegrpc.New(s, "tcp", addr, pidPath, log.StandardLogger())
...
In a terminal trigger a graceful server restart (using the pid from your output):
kill -USR2 pid
Run with supervisor
command = /path/to/pidproxy.py /path/to/pidPath /path/to/server
kill -USR2 {pidproxy.py pid}