mirror of https://github.com/grafana/grafana.git
				
				
				
			Fail when server is unable to bind port (#20409)
* Server: Return error when unable to bind port * Server: Exit if a service fails * Build: Remove graceful kill from Bra config
This commit is contained in:
		
							parent
							
								
									85b7ddefc0
								
							
						
					
					
						commit
						82f4fc2783
					
				|  | @ -17,5 +17,3 @@ cmds = [ | ||||||
|   ["go", "run", "-mod=vendor", "build.go", "-dev", "build-server"], |   ["go", "run", "-mod=vendor", "build.go", "-dev", "build-server"], | ||||||
| 	["./bin/grafana-server", "-packaging=dev", "cfg:app_mode=development"] | 	["./bin/grafana-server", "-packaging=dev", "cfg:app_mode=development"] | ||||||
| ] | ] | ||||||
| interrupt_timout = 5 |  | ||||||
| graceful_kill = true |  | ||||||
|  |  | ||||||
|  | @ -29,6 +29,7 @@ import ( | ||||||
| 	"github.com/grafana/grafana/pkg/services/quota" | 	"github.com/grafana/grafana/pkg/services/quota" | ||||||
| 	"github.com/grafana/grafana/pkg/services/rendering" | 	"github.com/grafana/grafana/pkg/services/rendering" | ||||||
| 	"github.com/grafana/grafana/pkg/setting" | 	"github.com/grafana/grafana/pkg/setting" | ||||||
|  | 	"github.com/grafana/grafana/pkg/util/errutil" | ||||||
| 	"github.com/prometheus/client_golang/prometheus" | 	"github.com/prometheus/client_golang/prometheus" | ||||||
| 	"github.com/prometheus/client_golang/prometheus/promhttp" | 	"github.com/prometheus/client_golang/prometheus/promhttp" | ||||||
| 	macaron "gopkg.in/macaron.v1" | 	macaron "gopkg.in/macaron.v1" | ||||||
|  | @ -93,8 +94,7 @@ func (hs *HTTPServer) Run(ctx context.Context) error { | ||||||
| 	listenAddr := fmt.Sprintf("%s:%s", setting.HttpAddr, setting.HttpPort) | 	listenAddr := fmt.Sprintf("%s:%s", setting.HttpAddr, setting.HttpPort) | ||||||
| 	listener, err := net.Listen("tcp", listenAddr) | 	listener, err := net.Listen("tcp", listenAddr) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		hs.log.Debug("server was shutdown gracefully") | 		return errutil.Wrapf(err, "failed to open listener on address %s", listenAddr) | ||||||
| 		return nil |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	hs.log.Info("HTTP Server Listen", "address", listener.Addr().String(), "protocol", setting.Protocol, "subUrl", setting.AppSubUrl, "socket", setting.SocketPath) | 	hs.log.Info("HTTP Server Listen", "address", listener.Addr().String(), "protocol", setting.Protocol, "subUrl", setting.AppSubUrl, "socket", setting.SocketPath) | ||||||
|  |  | ||||||
|  | @ -103,7 +103,7 @@ func (s *Server) Run() (err error) { | ||||||
| 		s.log.Info("Initializing " + service.Name) | 		s.log.Info("Initializing " + service.Name) | ||||||
| 
 | 
 | ||||||
| 		if err := service.Instance.Init(); err != nil { | 		if err := service.Instance.Init(); err != nil { | ||||||
| 			return fmt.Errorf("Service init failed: %v", err) | 			return errutil.Wrapf(err, "Service init failed") | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -126,18 +126,21 @@ func (s *Server) Run() (err error) { | ||||||
| 				return nil | 				return nil | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			if err := service.Run(s.context); err != nil { | 			err := service.Run(s.context) | ||||||
|  | 			// Mark that we are in shutdown mode
 | ||||||
|  | 			// So no more services are started
 | ||||||
|  | 			s.shutdownInProgress = true | ||||||
|  | 			if err != nil { | ||||||
| 				if err != context.Canceled { | 				if err != context.Canceled { | ||||||
| 					// Server has crashed.
 | 					// Server has crashed.
 | ||||||
| 					s.log.Error("Stopped "+descriptor.Name, "reason", err) | 					s.log.Error("Stopped "+descriptor.Name, "reason", err) | ||||||
| 				} else { | 				} else { | ||||||
| 					s.log.Info("Stopped "+descriptor.Name, "reason", err) | 					s.log.Info("Stopped "+descriptor.Name, "reason", err) | ||||||
| 				} | 				} | ||||||
|  | 
 | ||||||
|  | 				return err | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			// Mark that we are in shutdown mode
 |  | ||||||
| 			// So more services are not started
 |  | ||||||
| 			s.shutdownInProgress = true |  | ||||||
| 			return nil | 			return nil | ||||||
| 		}) | 		}) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue