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:
parent
bec13a45cd
commit
a1c6cdf193
12
options.go
12
options.go
@ -31,6 +31,8 @@ type Options struct {
|
|||||||
// Other options for implementations of the interface
|
// Other options for implementations of the interface
|
||||||
// can be stored in a context
|
// can be stored in a context
|
||||||
Context context.Context
|
Context context.Context
|
||||||
|
|
||||||
|
Signal bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func newOptions(opts ...Option) Options {
|
func newOptions(opts ...Option) Options {
|
||||||
@ -42,6 +44,7 @@ func newOptions(opts ...Option) Options {
|
|||||||
Registry: registry.DefaultRegistry,
|
Registry: registry.DefaultRegistry,
|
||||||
Transport: transport.DefaultTransport,
|
Transport: transport.DefaultTransport,
|
||||||
Context: context.Background(),
|
Context: context.Background(),
|
||||||
|
Signal: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, o := range opts {
|
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 {
|
func Server(s server.Server) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.Server = s
|
o.Server = s
|
||||||
|
@ -169,7 +169,9 @@ func (s *service) Run() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ch := make(chan os.Signal, 1)
|
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 {
|
select {
|
||||||
// wait on kill signal
|
// wait on kill signal
|
||||||
|
Loading…
Reference in New Issue
Block a user