mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
avoid calling os.Exit outside main.go (#12459)
I don't think we should call os.Exit outside main.go. Calling os.Exit breaks the application control flow.
This commit is contained in:
committed by
Torkel Ödegaard
parent
7a4858dd11
commit
88783d6e0a
@@ -14,6 +14,7 @@ import (
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
|
||||
"github.com/grafana/grafana/pkg/log"
|
||||
"github.com/grafana/grafana/pkg/metrics"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
|
||||
@@ -87,7 +88,11 @@ func main() {
|
||||
|
||||
err := server.Run()
|
||||
|
||||
server.Exit(err)
|
||||
code := server.Exit(err)
|
||||
trace.Stop()
|
||||
log.Close()
|
||||
|
||||
os.Exit(code)
|
||||
}
|
||||
|
||||
func listenToSystemSignals(server *GrafanaServerImpl) {
|
||||
|
@@ -175,7 +175,7 @@ func (g *GrafanaServerImpl) Shutdown(reason string) {
|
||||
g.childRoutines.Wait()
|
||||
}
|
||||
|
||||
func (g *GrafanaServerImpl) Exit(reason error) {
|
||||
func (g *GrafanaServerImpl) Exit(reason error) int {
|
||||
// default exit code is 1
|
||||
code := 1
|
||||
|
||||
@@ -185,9 +185,7 @@ func (g *GrafanaServerImpl) Exit(reason error) {
|
||||
}
|
||||
|
||||
g.log.Error("Server shutdown", "reason", reason)
|
||||
|
||||
log.Close()
|
||||
os.Exit(code)
|
||||
return code
|
||||
}
|
||||
|
||||
func (g *GrafanaServerImpl) writePIDFile() {
|
||||
|
Reference in New Issue
Block a user