Skip to content

Commit

Permalink
Fixed loading config path
Browse files Browse the repository at this point in the history
  • Loading branch information
SlyngDK committed Nov 26, 2021
1 parent 2be87d0 commit 3d02558
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
20 changes: 17 additions & 3 deletions cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,24 @@ func initConfig() {
config = nebula.NewConfig(l)

if configPath == "" {
configPath = getConfigDir()
configPath = getConfigPath()
}

if configPath != "" {
configDir = filepath.Dir(configPath)
err := config.Load(configPath)

configPathInfo, err := os.Stat(configPath)
if err != nil {
l.WithError(err).Errorln("failed to load config")
os.Exit(1)
}

if configPathInfo.IsDir() {
configDir = configPath
} else {
configDir = filepath.Dir(configPath)
}

err = config.Load(configPath)
if err != nil {
l.WithError(err).Errorln("failed to load config")
os.Exit(1)
Expand All @@ -96,6 +108,8 @@ func initConfig() {
l.Errorf("failed to detect config path")
os.Exit(1)
}
l.Tracef("using config: %s", configPath)
l.Tracef("using config dir: %s", configDir)
}

func main() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/agent/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func dirExists(path string) (bool, os.FileInfo) {
return fileinfo.IsDir(), fileinfo
}

func getConfigDir() string {
func getConfigPath() string {
ok, _ := dirExists("/etc/nebula-provisioner")
if ok {
return "/etc/nebula-provisioner"
Expand Down

0 comments on commit 3d02558

Please sign in to comment.