8 "github.com/Sirupsen/logrus"
9 "github.com/codegangsta/cli"
12 // Config parameters (json format) of /config command
14 Version string `json:"version"`
15 APIVersion string `json:"apiVersion"`
16 VersionGitTag string `json:"gitTag"`
17 Builder BuilderConfig `json:"builder"`
18 Folders FoldersConfig `json:"folders"`
20 // Private (un-exported fields in REST GET /config route)
21 FileConf FileConfig `json:"-"`
22 WebAppDir string `json:"-"`
23 HTTPPort string `json:"-"`
24 ShareRootDir string `json:"-"`
25 Log *logrus.Logger `json:"-"`
28 // Config default values
30 DefaultAPIVersion = "1"
32 DefaultShareDir = "/mnt/share"
35 // Init loads the configuration on start-up
36 func Init(cliCtx *cli.Context, log *logrus.Logger) (*Config, error) {
39 // Define default configuration
41 Version: cliCtx.App.Metadata["version"].(string),
42 APIVersion: DefaultAPIVersion,
43 VersionGitTag: cliCtx.App.Metadata["git-tag"].(string),
44 Builder: BuilderConfig{},
45 Folders: FoldersConfig{},
47 WebAppDir: "webapp/dist",
48 HTTPPort: DefaultPort,
49 ShareRootDir: DefaultShareDir,
53 // config file settings overwrite default config
54 err = updateConfigFromFile(&c, cliCtx.GlobalString("config"))
59 // Update location of shared dir if needed
60 if !dirExists(c.ShareRootDir) {
61 if err := os.MkdirAll(c.ShareRootDir, 0770); err != nil {
62 return nil, fmt.Errorf("No valid shared directory found: %v", err)
65 c.Log.Infoln("Share root directory: ", c.ShareRootDir)
67 if c.FileConf.LogsDir != "" && !dirExists(c.FileConf.LogsDir) {
68 if err := os.MkdirAll(c.FileConf.LogsDir, 0770); err != nil {
69 return nil, fmt.Errorf("Cannot create logs dir: %v", err)
72 c.Log.Infoln("Logs directory: ", c.FileConf.LogsDir)
77 func dirExists(path string) bool {
78 _, err := os.Stat(path)
79 if os.IsNotExist(err) {