10690: Fix conflicting uses of "config" name.
[arvados.git] / services / keep-balance / main.go
index 60349e91d8b9064c9715db9c701cd9b11b9ef8d3..04d3e9992b21f74289919dfeb5a67bda509e94f6 100644 (file)
@@ -13,6 +13,8 @@ import (
        "git.curoverse.com/arvados.git/sdk/go/config"
 )
 
        "git.curoverse.com/arvados.git/sdk/go/config"
 )
 
+const defaultConfigPath = "/etc/arvados/keep-balance/keep-balance.yml"
+
 // Config specifies site configuration, like API credentials and the
 // choice of which servers are to be balanced.
 //
 // Config specifies site configuration, like API credentials and the
 // choice of which servers are to be balanced.
 //
@@ -62,10 +64,10 @@ type RunOptions struct {
 var debugf = func(string, ...interface{}) {}
 
 func main() {
 var debugf = func(string, ...interface{}) {}
 
 func main() {
-       var config Config
+       var cfg Config
        var runOptions RunOptions
 
        var runOptions RunOptions
 
-       configPath := flag.String("config", "",
+       configPath := flag.String("config", defaultConfigPath,
                "`path` of JSON or YAML configuration file")
        serviceListPath := flag.String("config.KeepServiceList", "",
                "`path` of JSON or YAML file with list of keep services to balance, as given by \"arv keep_service list\" "+
                "`path` of JSON or YAML configuration file")
        serviceListPath := flag.String("config.KeepServiceList", "",
                "`path` of JSON or YAML file with list of keep services to balance, as given by \"arv keep_service list\" "+
@@ -76,22 +78,24 @@ func main() {
                "send pull requests (make more replicas of blocks that are underreplicated or are not in optimal rendezvous probe order)")
        flag.BoolVar(&runOptions.CommitTrash, "commit-trash", false,
                "send trash requests (delete unreferenced old blocks, and excess replicas of overreplicated blocks)")
                "send pull requests (make more replicas of blocks that are underreplicated or are not in optimal rendezvous probe order)")
        flag.BoolVar(&runOptions.CommitTrash, "commit-trash", false,
                "send trash requests (delete unreferenced old blocks, and excess replicas of overreplicated blocks)")
+       dumpConfig := flag.Bool("dump-config", false, "write current configuration to stdout and exit")
        dumpFlag := flag.Bool("dump", false, "dump details for each block to stdout")
        debugFlag := flag.Bool("debug", false, "enable debug messages")
        flag.Usage = usage
        flag.Parse()
 
        dumpFlag := flag.Bool("dump", false, "dump details for each block to stdout")
        debugFlag := flag.Bool("debug", false, "enable debug messages")
        flag.Usage = usage
        flag.Parse()
 
-       if *configPath == "" {
-               log.Fatal("You must specify a config file (see `keep-balance -help`)")
-       }
-       mustReadConfig(&config, *configPath)
+       mustReadConfig(&cfg, *configPath)
        if *serviceListPath != "" {
        if *serviceListPath != "" {
-               mustReadConfig(&config.KeepServiceList, *serviceListPath)
+               mustReadConfig(&cfg.KeepServiceList, *serviceListPath)
+       }
+
+       if *dumpConfig {
+               log.Fatal(config.DumpAndExit(cfg))
        }
 
        if *debugFlag {
                debugf = log.Printf
        }
 
        if *debugFlag {
                debugf = log.Printf
-               if j, err := json.Marshal(config); err != nil {
+               if j, err := json.Marshal(cfg); err != nil {
                        log.Fatal(err)
                } else {
                        log.Printf("config is %s", j)
                        log.Fatal(err)
                } else {
                        log.Printf("config is %s", j)
@@ -100,13 +104,13 @@ func main() {
        if *dumpFlag {
                runOptions.Dumper = log.New(os.Stdout, "", log.LstdFlags)
        }
        if *dumpFlag {
                runOptions.Dumper = log.New(os.Stdout, "", log.LstdFlags)
        }
-       err := CheckConfig(config, runOptions)
+       err := CheckConfig(cfg, runOptions)
        if err != nil {
                // (don't run)
        } else if runOptions.Once {
        if err != nil {
                // (don't run)
        } else if runOptions.Once {
-               _, err = (&Balancer{}).Run(config, runOptions)
+               _, err = (&Balancer{}).Run(cfg, runOptions)
        } else {
        } else {
-               err = RunForever(config, runOptions, nil)
+               err = RunForever(cfg, runOptions, nil)
        }
        if err != nil {
                log.Fatal(err)
        }
        if err != nil {
                log.Fatal(err)