gracegrpc

package module
v0.0.0-...-a940746 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2018 License: MIT Imports: 8 Imported by: 0

README

gracegrpc is used to wrap a grpc server that can be gracefully terminated & restarted.

LICENSE Build Status Go Report Card Godoc

Installation

go get github.com/0x5010/gracegrpc

Usage

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}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GraceGrpc

type GraceGrpc struct {
	// contains filtered or unexported fields
}

GraceGrpc is used to wrap a grpc server that can be gracefully terminated & restarted

func New

func New(s *grpc.Server, net, addr, pidPath string, l logger) (*GraceGrpc, error)

New is used to construct a new GraceGrpc

func (*GraceGrpc) Serve

func (gr *GraceGrpc) Serve() error

Serve is used to start grpc server. Serve will gracefully terminated or restarted when handling signals.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL