Skip to content

Commit 82f4fc2

Browse files
authored
Fail when server is unable to bind port (grafana#20409)
* Server: Return error when unable to bind port * Server: Exit if a service fails * Build: Remove graceful kill from Bra config
1 parent 85b7dde commit 82f4fc2

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

.bra.toml

-2
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,3 @@ cmds = [
1717
["go", "run", "-mod=vendor", "build.go", "-dev", "build-server"],
1818
["./bin/grafana-server", "-packaging=dev", "cfg:app_mode=development"]
1919
]
20-
interrupt_timout = 5
21-
graceful_kill = true

pkg/api/http_server.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/grafana/grafana/pkg/services/quota"
3030
"github.com/grafana/grafana/pkg/services/rendering"
3131
"github.com/grafana/grafana/pkg/setting"
32+
"github.com/grafana/grafana/pkg/util/errutil"
3233
"github.com/prometheus/client_golang/prometheus"
3334
"github.com/prometheus/client_golang/prometheus/promhttp"
3435
macaron "gopkg.in/macaron.v1"
@@ -93,8 +94,7 @@ func (hs *HTTPServer) Run(ctx context.Context) error {
9394
listenAddr := fmt.Sprintf("%s:%s", setting.HttpAddr, setting.HttpPort)
9495
listener, err := net.Listen("tcp", listenAddr)
9596
if err != nil {
96-
hs.log.Debug("server was shutdown gracefully")
97-
return nil
97+
return errutil.Wrapf(err, "failed to open listener on address %s", listenAddr)
9898
}
9999

100100
hs.log.Info("HTTP Server Listen", "address", listener.Addr().String(), "protocol", setting.Protocol, "subUrl", setting.AppSubUrl, "socket", setting.SocketPath)

pkg/cmd/grafana-server/server.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (s *Server) Run() (err error) {
103103
s.log.Info("Initializing " + service.Name)
104104

105105
if err := service.Instance.Init(); err != nil {
106-
return fmt.Errorf("Service init failed: %v", err)
106+
return errutil.Wrapf(err, "Service init failed")
107107
}
108108
}
109109

@@ -126,18 +126,21 @@ func (s *Server) Run() (err error) {
126126
return nil
127127
}
128128

129-
if err := service.Run(s.context); err != nil {
129+
err := service.Run(s.context)
130+
// Mark that we are in shutdown mode
131+
// So no more services are started
132+
s.shutdownInProgress = true
133+
if err != nil {
130134
if err != context.Canceled {
131135
// Server has crashed.
132136
s.log.Error("Stopped "+descriptor.Name, "reason", err)
133137
} else {
134138
s.log.Info("Stopped "+descriptor.Name, "reason", err)
135139
}
140+
141+
return err
136142
}
137143

138-
// Mark that we are in shutdown mode
139-
// So more services are not started
140-
s.shutdownInProgress = true
141144
return nil
142145
})
143146
}

0 commit comments

Comments
 (0)