mirror of
				https://github.com/go-micro/go-micro.git
				synced 2025-10-30 23:27:41 +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:
		
				
					committed by
					
						 Asim Aslam
						Asim Aslam
					
				
			
			
				
	
			
			
			
						parent
						
							bec13a45cd
						
					
				
				
					commit
					a1c6cdf193
				
			
							
								
								
									
										12
									
								
								options.go
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								options.go
									
									
									
									
									
								
							| @@ -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 | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user