Commit 88783d6e by Carl Bergquist Committed by Torkel Ödegaard

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.
parent 7a4858dd
......@@ -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() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment