aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-09-19 10:25:55 +0200
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-09-19 10:25:55 +0200
commit3f1c6dbe6b6422d8fdb70a2ef1899b9c32d1fc7e (patch)
treec8c876a6691dc160c09d238ded4d3f407e84899c
parent1c6af6236743aa0963d4919b5ef42627efa6aca7 (diff)
Rework search directories for agent-config.json files.
Here is the logic to determine which `agent-config.json` file will be used: 1. from command line option: `--config myConfig.json` 2. `$HOME/.xds/agent/agent-config.json` file 3. `/etc/xds-agent/agent-config.json` file 4. `<xds-agent executable dir>/agent-config.json` file
-rw-r--r--README.md2
-rw-r--r--lib/xdsconfig/fileconfig.go19
2 files changed, 14 insertions, 7 deletions
diff --git a/README.md b/README.md
index aadaf4c..312ffd1 100644
--- a/README.md
+++ b/README.md
@@ -80,7 +80,7 @@ Here is the logic to determine which `agent-config.json` file will be used:
1. from command line option: `--config myConfig.json`
1. `$HOME/.xds/agent/agent-config.json` file
-1. `<current dir>/agent-config.json` file
+1. `/etc/xds-agent/agent-config.json` file
1. `<xds-agent executable dir>/agent-config.json` file
Supported fields in configuration file are (all fields are optional and example
diff --git a/lib/xdsconfig/fileconfig.go b/lib/xdsconfig/fileconfig.go
index 2358a31..efe94bf 100644
--- a/lib/xdsconfig/fileconfig.go
+++ b/lib/xdsconfig/fileconfig.go
@@ -40,14 +40,21 @@ func updateConfigFromFile(c *Config, confFile string) (*FileConfig, error) {
if usr, err := user.Current(); err == nil {
searchIn = append(searchIn, path.Join(usr.HomeDir, ".xds", "agent", "agent-config.json"))
}
- cwd, err := os.Getwd()
- if err == nil {
- searchIn = append(searchIn, path.Join(cwd, "agent-config.json"))
- }
- exePath, err := filepath.Abs(filepath.Dir(os.Args[0]))
+
+ searchIn = append(searchIn, "/etc/xds-agent/agent-config.json")
+
+ exePath := os.Args[0]
+ ee, _ := os.Executable()
+ exeAbsPath, err := filepath.Abs(ee)
if err == nil {
- searchIn = append(searchIn, path.Join(exePath, "agent-config.json"))
+ exePath, err = filepath.EvalSymlinks(exeAbsPath)
+ if err == nil {
+ exePath = filepath.Dir(ee)
+ } else {
+ exePath = filepath.Dir(exeAbsPath)
+ }
}
+ searchIn = append(searchIn, path.Join(exePath, "agent-config.json"))
var cFile *string
for _, p := range searchIn {