Skip to content

Commit

Permalink
add option for web service signal handler (micro#1091)
Browse files Browse the repository at this point in the history
  • Loading branch information
shikbupt authored and asim committed Jan 10, 2020
1 parent 37d1139 commit 32a2005
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 12 additions & 0 deletions web/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ type Options struct {

// Static directory
StaticDir string

Signal bool
}

func newOptions(opts ...Option) Options {
Expand All @@ -59,6 +61,7 @@ func newOptions(opts ...Option) Options {
StaticDir: DefaultStaticDir,
Service: micro.NewService(),
Context: context.TODO(),
Signal: true,
}

for _, o := range opts {
Expand Down Expand Up @@ -242,3 +245,12 @@ func RegisterCheck(fn func(context.Context) error) Option {
o.RegisterCheck = fn
}
}

// 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
}
}
4 changes: 3 additions & 1 deletion web/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,9 @@ func (s *service) Run() error {
go s.run(ex)

ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT)
if s.opts.Signal {
signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT)
}

select {
// wait on kill signal
Expand Down

0 comments on commit 32a2005

Please sign in to comment.