summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/syncthing/st.go2
-rw-r--r--lib/webserver/server.go4
-rw-r--r--lib/xdsconfig/config.go26
-rw-r--r--lib/xdsconfig/fileconfig.go32
4 files changed, 51 insertions, 13 deletions
diff --git a/lib/syncthing/st.go b/lib/syncthing/st.go
index 5086994..c76db5a 100644
--- a/lib/syncthing/st.go
+++ b/lib/syncthing/st.go
@@ -114,7 +114,7 @@ func NewSyncThing(conf *xdsconfig.Config, log *logrus.Logger) *SyncThing {
if binDir == "" {
if binDir, err = filepath.Abs(filepath.Dir(os.Args[0])); err != nil {
- binDir = "/usr/local/bin"
+ binDir = "/opt/AGL/bin"
}
}
diff --git a/lib/webserver/server.go b/lib/webserver/server.go
index 8639b66..a2fdf6f 100644
--- a/lib/webserver/server.go
+++ b/lib/webserver/server.go
@@ -116,7 +116,9 @@ func (s *Server) Serve() error {
// Serve in the background
serveError := make(chan error, 1)
go func() {
- fmt.Printf("Web Server running on localhost:%s ...\n", s.cfg.FileConf.HTTPPort)
+ msg := fmt.Sprintf("Web Server running on localhost:%s ...\n", s.cfg.FileConf.HTTPPort)
+ s.log.Infof(msg)
+ fmt.Printf(msg)
serveError <- http.ListenAndServe(":"+s.cfg.FileConf.HTTPPort, s.router)
}()
diff --git a/lib/xdsconfig/config.go b/lib/xdsconfig/config.go
index 82ca97f..53d1639 100644
--- a/lib/xdsconfig/config.go
+++ b/lib/xdsconfig/config.go
@@ -4,6 +4,7 @@ import (
"fmt"
"io"
"os"
+ "path/filepath"
"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
@@ -62,6 +63,7 @@ func Init(cliCtx *cli.Context, log *logrus.Logger) (*Config, error) {
ShareRootDir: DefaultShareDir,
SdkRootDir: DefaultSdkRootDir,
HTTPPort: DefaultPort,
+ LogsDir: "",
},
Log: log,
}
@@ -80,11 +82,35 @@ func Init(cliCtx *cli.Context, log *logrus.Logger) (*Config, error) {
}
c.Log.Infoln("Share root directory: ", c.FileConf.ShareRootDir)
+ // Where Logs are redirected:
+ // default 'stdout' (logfile option default value)
+ // else use file (or filepath) set by --logfile option
+ // that may be overwritten by LogsDir field of config file
+ logF := c.Options.LogFile
+ logD := c.FileConf.LogsDir
+ if logF != "stdout" {
+ if logD != "" {
+ lf := filepath.Base(logF)
+ if lf == "" || lf == "." {
+ lf = "xds-server.log"
+ }
+ logF = filepath.Join(logD, lf)
+ } else {
+ logD = filepath.Dir(logF)
+ }
+ }
+ if logD == "" || logD == "." {
+ logD = "/tmp/xds/logs"
+ }
+ c.Options.LogFile = logF
+ c.FileConf.LogsDir = logD
+
if c.FileConf.LogsDir != "" && !common.Exists(c.FileConf.LogsDir) {
if err := os.MkdirAll(c.FileConf.LogsDir, 0770); err != nil {
return nil, fmt.Errorf("Cannot create logs dir: %v", err)
}
}
+ c.Log.Infoln("Logs file: ", c.Options.LogFile)
c.Log.Infoln("Logs directory: ", c.FileConf.LogsDir)
return &c, nil
diff --git a/lib/xdsconfig/fileconfig.go b/lib/xdsconfig/fileconfig.go
index 2dbf884..a0724af 100644
--- a/lib/xdsconfig/fileconfig.go
+++ b/lib/xdsconfig/fileconfig.go
@@ -13,7 +13,7 @@ import (
const (
// ConfigDir Directory in user HOME directory where xds config will be saved
- ConfigDir = ".xds"
+ ConfigDir = ".xds-server"
// GlobalConfigFilename Global config filename
GlobalConfigFilename = "config.json"
// FoldersConfigFilename Folders config filename
@@ -42,8 +42,8 @@ type FileConfig struct {
// readGlobalConfig reads configuration from a config file.
// Order to determine which config file is used:
// 1/ from command line option: "--config myConfig.json"
-// 2/ $HOME/.xds/config.json file
-// 3/ <current_dir>/config.json file
+// 2/ $HOME/.xds-server/config.json file
+// 3/ /etc/xds-server/config.json file
// 4/ <xds-server executable dir>/config.json file
func readGlobalConfig(c *Config, confFile string) error {
@@ -55,14 +55,20 @@ func readGlobalConfig(c *Config, confFile string) error {
searchIn = append(searchIn, path.Join(usr.HomeDir, ConfigDir,
GlobalConfigFilename))
}
- cwd, err := os.Getwd()
- if err == nil {
- searchIn = append(searchIn, path.Join(cwd, "config.json"))
- }
- exePath, err := filepath.Abs(filepath.Dir(os.Args[0]))
+
+ searchIn = append(searchIn, "/etc/xds-server/config.json")
+
+ exePath := os.Args[0]
+ exeAbsPath, err := filepath.Abs(os.Args[0])
if err == nil {
- searchIn = append(searchIn, path.Join(exePath, "config.json"))
+ exePath, err = filepath.EvalSymlinks(exeAbsPath)
+ if err == nil {
+ exePath = filepath.Dir(exePath)
+ } else {
+ exePath = filepath.Dir(exeAbsPath)
+ }
}
+ searchIn = append(searchIn, path.Join(exePath, "config.json"))
var cFile *string
for _, p := range searchIn {
@@ -75,7 +81,6 @@ func readGlobalConfig(c *Config, confFile string) error {
// No config file found
return nil
}
-
c.Log.Infof("Use config file: %s", *cFile)
// TODO move on viper package to support comments in JSON and also
@@ -117,12 +122,17 @@ func readGlobalConfig(c *Config, confFile string) error {
if fCfg.HTTPPort == "" {
fCfg.HTTPPort = c.FileConf.HTTPPort
}
+ if fCfg.LogsDir == "" {
+ fCfg.LogsDir = c.FileConf.LogsDir
+ }
// Resolve webapp dir (support relative or full path)
fCfg.WebAppDir = strings.Trim(fCfg.WebAppDir, " ")
if !strings.HasPrefix(fCfg.WebAppDir, "/") && exePath != "" {
+ cwd, _ := os.Getwd()
+
// Check first from current directory
- for _, rootD := range []string{cwd, exePath} {
+ for _, rootD := range []string{exePath, cwd} {
ff := path.Join(rootD, fCfg.WebAppDir, "index.html")
if common.Exists(ff) {
fCfg.WebAppDir = path.Join(rootD, fCfg.WebAppDir)