mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Changes to config file loading
This commit is contained in:
parent
ad4cf373a6
commit
29c9330965
@ -6,7 +6,7 @@ init_cmds = [
|
|||||||
watch_all = true
|
watch_all = true
|
||||||
watch_dirs = [
|
watch_dirs = [
|
||||||
"$WORKDIR/pkg",
|
"$WORKDIR/pkg",
|
||||||
"$WORKDIR/templates",
|
"$WORKDIR/grafana/src/views",
|
||||||
"$WORKDIR/conf",
|
"$WORKDIR/conf",
|
||||||
]
|
]
|
||||||
watch_exts = [".go", ".ini"]
|
watch_exts = [".go", ".ini"]
|
||||||
|
108
conf/grafana.dev.ini
Normal file
108
conf/grafana.dev.ini
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
app_name = Grafana
|
||||||
|
app_mode = development
|
||||||
|
|
||||||
|
[server]
|
||||||
|
protocol = http
|
||||||
|
domain = localhost
|
||||||
|
root_url = %(protocol)s://%(domain)s:%(http_port)s/
|
||||||
|
http_addr =
|
||||||
|
http_port = 3000
|
||||||
|
router_logging = false
|
||||||
|
static_root_path = grafana/src
|
||||||
|
|
||||||
|
[session]
|
||||||
|
; Either "memory", "file", default is "memory"
|
||||||
|
provider = file
|
||||||
|
; Provider config options
|
||||||
|
; memory: not have any config yet
|
||||||
|
; file: session file path, e.g. `data/sessions`
|
||||||
|
; redis: config like redis server addr, poolSize, password, e.g. `127.0.0.1:6379,100,grafana`
|
||||||
|
; mysql: go-sql-driver/mysql dsn config string, e.g. `root:password@/session_table`
|
||||||
|
provider_config = data/sessions
|
||||||
|
; Session cookie name
|
||||||
|
cookie_name = grafana_sess
|
||||||
|
; If you use session in https only, default is false
|
||||||
|
cookie_secure = false
|
||||||
|
; Enable set cookie, default is true
|
||||||
|
enable_set_cookie = true
|
||||||
|
; Session GC time interval, default is 86400
|
||||||
|
gc_time_interval = 86400
|
||||||
|
; Session life time, default is 86400
|
||||||
|
session_life_time = 86400
|
||||||
|
; session id hash func, Either "sha1", "sha256" or "md5" default is sha1
|
||||||
|
session_id_hashfunc = sha1
|
||||||
|
; Session hash key, default is use random string
|
||||||
|
session_id_hashkey =
|
||||||
|
|
||||||
|
[oauth]
|
||||||
|
enabled = true
|
||||||
|
|
||||||
|
[oauth.github]
|
||||||
|
enabled = true
|
||||||
|
client_id = de054205006b9baa2e17
|
||||||
|
client_secret = 72b7ea52d9f1096fdf36cea95e95362a307e0322
|
||||||
|
scopes = user:email
|
||||||
|
auth_url = https://github.com/login/oauth/authorize
|
||||||
|
token_url = https://github.com/login/oauth/access_token
|
||||||
|
|
||||||
|
[oauth.google]
|
||||||
|
enabled = true
|
||||||
|
client_id = 106011922963-4pvl05e9urtrm8bbqr0vouosj3e8p8kb.apps.googleusercontent.com
|
||||||
|
client_secret = K2evIa4QhfbhhAm3SO72t2Zv
|
||||||
|
scopes = https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email
|
||||||
|
auth_url = https://accounts.google.com/o/oauth2/auth
|
||||||
|
token_url = https://accounts.google.com/o/oauth2/token
|
||||||
|
|
||||||
|
[database]
|
||||||
|
; Either "mysql", "postgres" or "sqlite3", it's your choice
|
||||||
|
type = sqlite3
|
||||||
|
host = 127.0.0.1:3306
|
||||||
|
name = grafana
|
||||||
|
user = root
|
||||||
|
PASSWD =
|
||||||
|
; For "postgres" only, either "disable", "require" or "verify-full"
|
||||||
|
ssl_mode = disable
|
||||||
|
; For "sqlite3" only
|
||||||
|
path = data/grafana.db
|
||||||
|
|
||||||
|
; [database]
|
||||||
|
; ; Either "mysql", "postgres" or "sqlite3", it's your choice
|
||||||
|
; type = postgres
|
||||||
|
; host = 127.0.0.1:5432
|
||||||
|
; name = grafana
|
||||||
|
; user = grafana
|
||||||
|
; password = grafana
|
||||||
|
; ; For "postgres" only, either "disable", "require" or "verify-full"
|
||||||
|
; ssl_mode = disable
|
||||||
|
; ; For "sqlite3" only
|
||||||
|
; path = data/grafana.db
|
||||||
|
;
|
||||||
|
[log]
|
||||||
|
root_path =
|
||||||
|
; Either "console", "file", "conn", "smtp" or "database", default is "console"
|
||||||
|
; Use comma to separate multiple modes, e.g. "console, file"
|
||||||
|
mode = console
|
||||||
|
; Buffer length of channel, keep it as it is if you don't know what it is.
|
||||||
|
buffer_len = 10000
|
||||||
|
; Either "Trace", "Debug", "Info", "Warn", "Error", "Critical", default is "Trace"
|
||||||
|
level = Trace
|
||||||
|
|
||||||
|
; For "console" mode only
|
||||||
|
[log.console]
|
||||||
|
level =
|
||||||
|
|
||||||
|
; For "file" mode only
|
||||||
|
[log.file]
|
||||||
|
level =
|
||||||
|
; This enables automated log rotate(switch of following options), default is true
|
||||||
|
log_rotate = true
|
||||||
|
; Max line number of single file, default is 1000000
|
||||||
|
max_lines = 1000000
|
||||||
|
; Max size shift of single file, default is 28 means 1 << 28, 256MB
|
||||||
|
max_lines_shift = 28
|
||||||
|
; Segment log daily, default is true
|
||||||
|
daily_rotate = true
|
||||||
|
; Expired days of log file(delete after max days), default is 7
|
||||||
|
max_days = 7
|
||||||
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
app_name = Grafana Pro Server
|
app_name = Grafana
|
||||||
app_mode = dev
|
app_mode = development
|
||||||
|
|
||||||
[server]
|
[server]
|
||||||
protocol = http
|
protocol = http
|
||||||
@ -7,8 +7,8 @@ domain = localhost
|
|||||||
root_url = %(protocol)s://%(domain)s:%(http_port)s/
|
root_url = %(protocol)s://%(domain)s:%(http_port)s/
|
||||||
http_addr =
|
http_addr =
|
||||||
http_port = 3000
|
http_port = 3000
|
||||||
ssh_port = 22
|
|
||||||
router_logging = false
|
router_logging = false
|
||||||
|
static_root_path = public
|
||||||
|
|
||||||
[session]
|
[session]
|
||||||
; Either "memory", "file", default is "memory"
|
; Either "memory", "file", default is "memory"
|
||||||
@ -16,11 +16,11 @@ provider = file
|
|||||||
; Provider config options
|
; Provider config options
|
||||||
; memory: not have any config yet
|
; memory: not have any config yet
|
||||||
; file: session file path, e.g. `data/sessions`
|
; file: session file path, e.g. `data/sessions`
|
||||||
; redis: config like redis server addr, poolSize, password, e.g. `127.0.0.1:6379,100,gogs`
|
; redis: config like redis server addr, poolSize, password, e.g. `127.0.0.1:6379,100,grafana`
|
||||||
; mysql: go-sql-driver/mysql dsn config string, e.g. `root:password@/session_table`
|
; mysql: go-sql-driver/mysql dsn config string, e.g. `root:password@/session_table`
|
||||||
provider_config = data/sessions
|
provider_config = data/sessions
|
||||||
; Session cookie name
|
; Session cookie name
|
||||||
cookie_name = grafana_pro_sess
|
cookie_name = grafana_sess
|
||||||
; If you use session in https only, default is false
|
; If you use session in https only, default is false
|
||||||
cookie_secure = false
|
cookie_secure = false
|
||||||
; Enable set cookie, default is true
|
; Enable set cookie, default is true
|
2
grafana
2
grafana
@ -1 +1 @@
|
|||||||
Subproject commit 33e3fc70b286e0a1ebee901006e8f70b63b69198
|
Subproject commit 7c72705bc5418ddf7030b3b50e86b236bd07e1fc
|
@ -25,7 +25,13 @@ var CmdWeb = cli.Command{
|
|||||||
Usage: "grafana web",
|
Usage: "grafana web",
|
||||||
Description: "Starts Grafana backend & web server",
|
Description: "Starts Grafana backend & web server",
|
||||||
Action: runWeb,
|
Action: runWeb,
|
||||||
Flags: []cli.Flag{},
|
Flags: []cli.Flag{
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "config",
|
||||||
|
Value: "grafana.ini",
|
||||||
|
Usage: "path to config file",
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func newMacaron() *macaron.Macaron {
|
func newMacaron() *macaron.Macaron {
|
||||||
@ -61,8 +67,8 @@ func mapStatic(m *macaron.Macaron, dir string, prefix string) {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
func runWeb(*cli.Context) {
|
func runWeb(c *cli.Context) {
|
||||||
log.Info("Starting Grafana-Pro v.2-alpha")
|
log.Info("Starting Grafana 2.0-alpha")
|
||||||
|
|
||||||
setting.NewConfigContext()
|
setting.NewConfigContext()
|
||||||
setting.InitServices()
|
setting.InitServices()
|
||||||
|
@ -57,6 +57,7 @@ var (
|
|||||||
SessionOptions session.Options
|
SessionOptions session.Options
|
||||||
|
|
||||||
// Global setting objects.
|
// Global setting objects.
|
||||||
|
WorkDir string
|
||||||
Cfg *goconfig.ConfigFile
|
Cfg *goconfig.ConfigFile
|
||||||
ConfRootPath string
|
ConfRootPath string
|
||||||
CustomPath string // Custom directory path.
|
CustomPath string // Custom directory path.
|
||||||
@ -74,42 +75,47 @@ func init() {
|
|||||||
log.NewLogger(0, "console", `{"level": 0}`)
|
log.NewLogger(0, "console", `{"level": 0}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func WorkDir() (string, error) {
|
func getWorkDir() string {
|
||||||
p, err := filepath.Abs(".")
|
p, _ := filepath.Abs(".")
|
||||||
if err != nil {
|
return p
|
||||||
return "", err
|
}
|
||||||
|
|
||||||
|
func findConfigFile() string {
|
||||||
|
WorkDir = getWorkDir()
|
||||||
|
ConfRootPath = path.Join(WorkDir, "conf")
|
||||||
|
|
||||||
|
configFile := path.Join(ConfRootPath, "grafana.ini")
|
||||||
|
//log.Info("Looking for config file: %v", configFile)
|
||||||
|
if com.IsFile(configFile) {
|
||||||
|
return configFile
|
||||||
}
|
}
|
||||||
return p, nil
|
configFile = path.Join(ConfRootPath, "grafana.dev.ini")
|
||||||
|
//log.Info("Looking for config file: %v", configFile)
|
||||||
|
if com.IsFile(configFile) {
|
||||||
|
return configFile
|
||||||
|
}
|
||||||
|
configFile = path.Join(ConfRootPath, "grafana.example.ini")
|
||||||
|
//log.Info("Looking for config file: %v", configFile)
|
||||||
|
if com.IsFile(configFile) {
|
||||||
|
return configFile
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Fatal(3, "Could not find any config file")
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfigContext() {
|
func NewConfigContext() {
|
||||||
workDir, err := WorkDir()
|
configFile := findConfigFile()
|
||||||
|
|
||||||
|
log.Info("Loading config file: %v", configFile)
|
||||||
|
var err error
|
||||||
|
|
||||||
|
Cfg, err = goconfig.LoadConfigFile(configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(4, "Fail to get work directory: %v", err)
|
log.Fatal(4, "Fail to parse %v, error: %v", configFile, err)
|
||||||
}
|
|
||||||
ConfRootPath = path.Join(workDir, "conf")
|
|
||||||
|
|
||||||
Cfg, err = goconfig.LoadConfigFile(path.Join(workDir, "conf/grafana.ini"))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(4, "Fail to parse '%v/conf/grafana.ini': %v", workDir, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CustomPath = os.Getenv("GRAFANA_CONF")
|
AppName = Cfg.MustValue("", "app_name", "Grafana")
|
||||||
|
|
||||||
if len(CustomPath) == 0 {
|
|
||||||
CustomPath = path.Join(workDir, "custom")
|
|
||||||
}
|
|
||||||
|
|
||||||
cfgPath := path.Join(CustomPath, "conf/grafana.ini")
|
|
||||||
if com.IsFile(cfgPath) {
|
|
||||||
if err = Cfg.AppendFiles(cfgPath); err != nil {
|
|
||||||
log.Fatal(4, "Fail to load custom 'conf/grafana.ini': %v", err)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.Warn("No custom 'conf/grafana.ini'")
|
|
||||||
}
|
|
||||||
|
|
||||||
AppName = Cfg.MustValue("", "app_name", "Grafana Pro")
|
|
||||||
AppUrl = Cfg.MustValue("server", "root_url", "http://localhost:3000/")
|
AppUrl = Cfg.MustValue("server", "root_url", "http://localhost:3000/")
|
||||||
if AppUrl[len(AppUrl)-1] != '/' {
|
if AppUrl[len(AppUrl)-1] != '/' {
|
||||||
AppUrl += "/"
|
AppUrl += "/"
|
||||||
@ -137,14 +143,14 @@ func NewConfigContext() {
|
|||||||
HttpPort = port
|
HttpPort = port
|
||||||
}
|
}
|
||||||
|
|
||||||
StaticRootPath = Cfg.MustValue("server", "static_root_path", path.Join(workDir, "grafana/src"))
|
StaticRootPath = Cfg.MustValue("server", "static_root_path", path.Join(WorkDir, "webapp"))
|
||||||
RouterLogging = Cfg.MustBool("server", "router_logging", false)
|
RouterLogging = Cfg.MustBool("server", "router_logging", false)
|
||||||
|
|
||||||
// PhantomJS rendering
|
// PhantomJS rendering
|
||||||
ImagesDir = "data/png"
|
ImagesDir = "data/png"
|
||||||
PhantomDir = "_vendor/phantomjs"
|
PhantomDir = "_vendor/phantomjs"
|
||||||
|
|
||||||
LogRootPath = Cfg.MustValue("log", "root_path", path.Join(workDir, "/data/log"))
|
LogRootPath = Cfg.MustValue("log", "root_path", path.Join(WorkDir, "/data/log"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func initSessionService() {
|
func initSessionService() {
|
||||||
|
Loading…
Reference in New Issue
Block a user