|
|
@@ -57,6 +57,7 @@ var (
|
|
|
SessionOptions session.Options
|
|
|
|
|
|
// Global setting objects.
|
|
|
+ WorkDir string
|
|
|
Cfg *goconfig.ConfigFile
|
|
|
ConfRootPath string
|
|
|
CustomPath string // Custom directory path.
|
|
|
@@ -74,42 +75,47 @@ func init() {
|
|
|
log.NewLogger(0, "console", `{"level": 0}`)
|
|
|
}
|
|
|
|
|
|
-func WorkDir() (string, error) {
|
|
|
- p, err := filepath.Abs(".")
|
|
|
- if err != nil {
|
|
|
- return "", err
|
|
|
- }
|
|
|
- return p, nil
|
|
|
+func getWorkDir() string {
|
|
|
+ p, _ := filepath.Abs(".")
|
|
|
+ return p
|
|
|
}
|
|
|
|
|
|
-func NewConfigContext() {
|
|
|
- workDir, err := WorkDir()
|
|
|
- if err != nil {
|
|
|
- log.Fatal(4, "Fail to get work directory: %v", err)
|
|
|
- }
|
|
|
- ConfRootPath = path.Join(workDir, "conf")
|
|
|
+func findConfigFile() string {
|
|
|
+ WorkDir = getWorkDir()
|
|
|
+ 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)
|
|
|
+ configFile := path.Join(ConfRootPath, "grafana.ini")
|
|
|
+ //log.Info("Looking for config file: %v", configFile)
|
|
|
+ if com.IsFile(configFile) {
|
|
|
+ return configFile
|
|
|
+ }
|
|
|
+ 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
|
|
|
}
|
|
|
|
|
|
- CustomPath = os.Getenv("GRAFANA_CONF")
|
|
|
+ log.Fatal(3, "Could not find any config file")
|
|
|
+ return ""
|
|
|
+}
|
|
|
|
|
|
- if len(CustomPath) == 0 {
|
|
|
- CustomPath = path.Join(workDir, "custom")
|
|
|
- }
|
|
|
+func NewConfigContext() {
|
|
|
+ configFile := findConfigFile()
|
|
|
+
|
|
|
+ log.Info("Loading config file: %v", configFile)
|
|
|
+ var err error
|
|
|
|
|
|
- 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'")
|
|
|
+ Cfg, err = goconfig.LoadConfigFile(configFile)
|
|
|
+ if err != nil {
|
|
|
+ log.Fatal(4, "Fail to parse %v, error: %v", configFile, err)
|
|
|
}
|
|
|
|
|
|
- AppName = Cfg.MustValue("", "app_name", "Grafana Pro")
|
|
|
+ AppName = Cfg.MustValue("", "app_name", "Grafana")
|
|
|
AppUrl = Cfg.MustValue("server", "root_url", "http://localhost:3000/")
|
|
|
if AppUrl[len(AppUrl)-1] != '/' {
|
|
|
AppUrl += "/"
|
|
|
@@ -137,14 +143,14 @@ func NewConfigContext() {
|
|
|
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)
|
|
|
|
|
|
// PhantomJS rendering
|
|
|
ImagesDir = "data/png"
|
|
|
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() {
|