Began work on refactoring reading config values

This commit is contained in:
Torkel Ödegaard
2015-04-08 20:31:42 +02:00
parent 9c2040aa9b
commit a991cda233
28 changed files with 83 additions and 3661 deletions
+2 -47
View File
@@ -5,38 +5,22 @@ package cmd
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"path"
"path/filepath"
"strconv"
"github.com/Unknwon/macaron"
"github.com/codegangsta/cli"
"github.com/grafana/grafana/pkg/api"
"github.com/grafana/grafana/pkg/api/static"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/metrics"
"github.com/grafana/grafana/pkg/middleware"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/services/eventpublisher"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/social"
)
var Web = cli.Command{
Name: "web",
Usage: "Starts Grafana backend & web server",
Description: "Starts Grafana backend & web server",
Action: runWeb,
}
func newMacaron() *macaron.Macaron {
macaron.Env = setting.Env
m := macaron.New()
m.Use(middleware.Logger())
m.Use(macaron.Recovery())
@@ -83,22 +67,12 @@ func mapStatic(m *macaron.Macaron, dir string, prefix string) {
))
}
func runWeb(c *cli.Context) {
initRuntime(c)
writePIDFile(c)
social.NewOAuthService()
eventpublisher.Init()
plugins.Init()
func StartServer() {
var err error
m := newMacaron()
api.Register(m)
if setting.ReportingEnabled {
go metrics.StartUsageReportLoop()
}
listenAddr := fmt.Sprintf("%s:%s", setting.HttpAddr, setting.HttpPort)
log.Info("Listen: %v://%s%s", setting.Protocol, listenAddr, setting.AppSubUrl)
switch setting.Protocol {
@@ -114,22 +88,3 @@ func runWeb(c *cli.Context) {
log.Fatal(4, "Fail to start server: %v", err)
}
}
func writePIDFile(c *cli.Context) {
path := c.GlobalString("pidfile")
if path == "" {
return
}
// Ensure the required directory structure exists.
err := os.MkdirAll(filepath.Dir(path), 0700)
if err != nil {
log.Fatal(3, "Failed to verify pid directory", err)
}
// Retrieve the PID and write it.
pid := strconv.Itoa(os.Getpid())
if err := ioutil.WriteFile(path, []byte(pid), 0644); err != nil {
log.Fatal(3, "Failed to write pidfile", err)
}
}