1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-24 10:07:04 +02:00

Now specify HandleSignal as an option to toggle signal handling. (#948)

Signed-off-by: Erik Hollensbe <github@hollensbe.org>
This commit is contained in:
Erik Hollensbe 2019-11-16 03:13:34 -08:00 committed by Asim Aslam
parent bec13a45cd
commit a1c6cdf193
2 changed files with 15 additions and 1 deletions

View File

@ -31,6 +31,8 @@ type Options struct {
// Other options for implementations of the interface
// can be stored in a context
Context context.Context
Signal bool
}
func newOptions(opts ...Option) Options {
@ -42,6 +44,7 @@ func newOptions(opts ...Option) Options {
Registry: registry.DefaultRegistry,
Transport: transport.DefaultTransport,
Context: context.Background(),
Signal: true,
}
for _, o := range opts {
@ -81,6 +84,15 @@ func Context(ctx context.Context) Option {
}
}
// HandleSignal toggles automatic installation of the signal handler that
// traps TERM, INT, and QUIT. Users of this feature to disable the signal
// handler, should control liveness of the service through the context.
func HandleSignal(b bool) Option {
return func(o *Options) {
o.Signal = b
}
}
func Server(s server.Server) Option {
return func(o *Options) {
o.Server = s

View File

@ -169,7 +169,9 @@ func (s *service) Run() error {
}
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT)
if s.opts.Signal {
signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT)
}
select {
// wait on kill signal