Skip to content

Commit

Permalink
agent: Fix log path initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
ish-hcc committed Sep 29, 2024
1 parent 809be1c commit 6ecd02c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
16 changes: 16 additions & 0 deletions agent/cmd/cm-honeybee-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/cloud-barista/cm-honeybee/agent/lib/privileged"
"github.com/cloud-barista/cm-honeybee/agent/pkg/api/rest/controller"
"github.com/cloud-barista/cm-honeybee/agent/pkg/api/rest/server"
"github.com/jollaman999/utils/fileutil"
"github.com/jollaman999/utils/logger"
"github.com/jollaman999/utils/syscheck"
"log"
Expand Down Expand Up @@ -39,6 +40,21 @@ func init() {
log.Fatalln(err)
}

common.RootPath = os.Getenv(common.ModuleROOT)
if len(common.RootPath) == 0 {
homeDir, err := os.UserHomeDir()
if err != nil {
log.Fatalln(err)
}

common.RootPath = homeDir + "/." + strings.ToLower(common.ModuleName)
}

err = fileutil.CreateDirIfNotExist(common.RootPath)
if err != nil {
log.Fatalln(err)
}

err = logger.InitLogFile(common.RootPath+"/log", strings.ToLower(common.ModuleName))
if err != nil {
log.Panicln(err)
Expand Down
15 changes: 0 additions & 15 deletions agent/lib/config/cm-honeybee.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,6 @@ func getCMHoneybeeAgentDefaultConfig() cmHoneybeeAgentConfig {
}

func readCMHoneybeeAgentConfigFile() error {
common.RootPath = os.Getenv(common.ModuleROOT)
if len(common.RootPath) == 0 {
homeDir, err := os.UserHomeDir()
if err != nil {
return err
}

common.RootPath = homeDir + "/." + strings.ToLower(common.ModuleName)
}

err := fileutil.CreateDirIfNotExist(common.RootPath)
if err != nil {
return err
}

ex, err := os.Executable()
if err != nil {
return err
Expand Down

0 comments on commit 6ecd02c

Please sign in to comment.