Skip to content

Commit

Permalink
config : try loading default configuration file /etc/skydive/skydive.yml
Browse files Browse the repository at this point in the history
If none is given, will not fail starting skydive if the file didn't exist
  • Loading branch information
nplanel committed Apr 5, 2018
1 parent b72bfac commit 7088f69
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
23 changes: 17 additions & 6 deletions cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,27 @@ import (
"github.com/skydive-project/skydive/logging"
)

const (
DefaultConfigurationFile = "/etc/skydive/skydive.yml"
)

// LoadConfiguration from a configuration file
func LoadConfiguration(cfgBackend string, cfgFiles []string) error {
if len(cfgFiles) != 0 {
if err := config.InitConfig(cfgBackend, cfgFiles); err != nil {
return fmt.Errorf("Failed to initialize config: %s", err.Error())
if len(cfgFiles) == 0 {
if err := config.InitConfig(cfgBackend, []string{DefaultConfigurationFile}); err == nil {
if err := logging.InitLogging(); err != nil {
return fmt.Errorf("Failed to initialize logging system: %s", err.Error())
}
}
return nil
}

if err := logging.InitLogging(); err != nil {
return fmt.Errorf("Failed to initialize logging system: %s", err.Error())
}
if err := config.InitConfig(cfgBackend, cfgFiles); err != nil {
return fmt.Errorf("Failed to initialize config: %s", err.Error())
}

if err := logging.InitLogging(); err != nil {
return fmt.Errorf("Failed to initialize logging system: %s", err.Error())
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/skydive/skydive.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var RootCmd = &cobra.Command{
}

func init() {
RootCmd.PersistentFlags().StringArrayVarP(&cmd.CfgFiles, "conf", "c", []string{"/etc/skydive/skydive.yml"}, "location of Skydive configuration files, default : /etc/skydive/skydive.yml")
RootCmd.PersistentFlags().StringArrayVarP(&cmd.CfgFiles, "conf", "c", []string{""}, "location of Skydive configuration files, default try loading /etc/skydive/skydive.yml")
RootCmd.PersistentFlags().StringVarP(&cmd.CfgBackend, "config-backend", "b", "file", "configuration backend (defaults to file)")

executable := path.Base(os.Args[0])
Expand Down

0 comments on commit 7088f69

Please sign in to comment.