forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
98 lines (78 loc) · 2.09 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"flag"
"io/ioutil"
"os"
"os/signal"
"path/filepath"
"runtime"
"strconv"
"time"
"github.com/grafana/grafana/pkg/cmd"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/metrics"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/services/eventpublisher"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/social"
)
var version = "master"
var commit = "NA"
var buildstamp string
var configFile = flag.String("config", "", "path to config file")
var homePath = flag.String("homepath", "", "path to grafana install/home path, defaults to working directory")
var pidFile = flag.String("pidfile", "", "path to pid file")
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
}
func main() {
buildstampInt64, _ := strconv.ParseInt(buildstamp, 10, 64)
setting.BuildVersion = version
setting.BuildCommit = commit
setting.BuildStamp = buildstampInt64
go func() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
os.Exit(0)
}()
flag.Parse()
initRuntime()
writePIDFile()
social.NewOAuthService()
eventpublisher.Init()
plugins.Init()
if setting.ReportingEnabled {
go metrics.StartUsageReportLoop()
}
cmd.StartServer()
log.Close()
}
func initRuntime() {
setting.NewConfigContext(&setting.CommandLineArgs{
Config: *configFile,
HomePath: *homePath,
Args: flag.Args(),
})
log.Info("Starting Grafana")
log.Info("Version: %v, Commit: %v, Build date: %v", setting.BuildVersion, setting.BuildCommit, time.Unix(setting.BuildStamp, 0))
setting.LogConfigurationInfo()
sqlstore.NewEngine()
sqlstore.EnsureAdminUser()
}
func writePIDFile() {
if *pidFile == "" {
return
}
// Ensure the required directory structure exists.
err := os.MkdirAll(filepath.Dir(*pidFile), 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(*pidFile, []byte(pid), 0644); err != nil {
log.Fatal(3, "Failed to write pidfile", err)
}
}