10690: Add -dump-config to arv-git-httpd, crunch-dispatch-slurm, keep-balance, keep...
authorTom Clegg <tom@curoverse.com>
Thu, 12 Jan 2017 15:33:16 +0000 (10:33 -0500)
committerTom Clegg <tom@curoverse.com>
Fri, 27 Jan 2017 22:04:03 +0000 (17:04 -0500)
services/arv-git-httpd/main.go
services/crunch-dispatch-slurm/crunch-dispatch-slurm.go
services/keep-balance/main.go
services/keep-web/main.go
services/keepproxy/keepproxy.go

index 75645ff47215c2b5f7f666057006ea2510f99811..3ff155714c1b0f2223b13fe30e254782034acc2a 100644 (file)
@@ -10,6 +10,7 @@ import (
        "git.curoverse.com/arvados.git/sdk/go/arvados"
        "git.curoverse.com/arvados.git/sdk/go/config"
        "github.com/coreos/go-systemd/daemon"
+       "github.com/ghodss/yaml"
 )
 
 // Server configuration
@@ -44,6 +45,7 @@ func main() {
                "Value for GITOLITE_HTTP_HOME environment variable. If not empty, GL_BYPASS_ACCESS_CHECKS=1 will also be set."+deprecated)
 
        cfgPath := flag.String("config", defaultCfgPath, "Configuration file `path`.")
+       dumpConfig := flag.Bool("dump-config", false, "write current configuration to stdout and exit (useful for migrating from command line flags to config file)")
        flag.Usage = usage
        flag.Parse()
 
@@ -63,6 +65,15 @@ func main() {
                }
        }
 
+       if *dumpConfig {
+               y, err := yaml.Marshal(theConfig)
+               if err != nil {
+                       log.Fatal(err)
+               }
+               os.Stdout.Write(y)
+               os.Exit(0)
+       }
+
        srv := &server{}
        if err := srv.Start(); err != nil {
                log.Fatal(err)
index e768b509cd6f2c69bb529d9e9a90e2d923e422ce..b62b24bc867aa41a3e5b57427e35294d501dd6d0 100644 (file)
@@ -5,11 +5,6 @@ package main
 import (
        "flag"
        "fmt"
-       "git.curoverse.com/arvados.git/sdk/go/arvados"
-       "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
-       "git.curoverse.com/arvados.git/sdk/go/config"
-       "git.curoverse.com/arvados.git/sdk/go/dispatch"
-       "github.com/coreos/go-systemd/daemon"
        "io"
        "io/ioutil"
        "log"
@@ -18,6 +13,13 @@ import (
        "os/exec"
        "strings"
        "time"
+
+       "git.curoverse.com/arvados.git/sdk/go/arvados"
+       "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
+       "git.curoverse.com/arvados.git/sdk/go/config"
+       "git.curoverse.com/arvados.git/sdk/go/dispatch"
+       "github.com/coreos/go-systemd/daemon"
+       "github.com/ghodss/yaml"
 )
 
 // Config used by crunch-dispatch-slurm
@@ -56,6 +58,10 @@ func doMain() error {
                "config",
                defaultConfigPath,
                "`path` to JSON or YAML configuration file")
+       dumpConfig := flag.Bool(
+               "dump-config",
+               false,
+               "write current configuration to stdout and exit")
 
        // Parse args; omit the first arg which is the command name
        flags.Parse(os.Args[1:])
@@ -89,6 +95,15 @@ func doMain() error {
                log.Printf("warning: Client credentials missing from config, so falling back on environment variables (deprecated).")
        }
 
+       if *dumpConfig {
+               y, err := yaml.Marshal(theConfig)
+               if err != nil {
+                       log.Fatal(err)
+               }
+               os.Stdout.Write(y)
+               os.Exit(0)
+       }
+
        arv, err := arvadosclient.MakeArvadosClient()
        if err != nil {
                log.Printf("Error making Arvados client: %v", err)
index 310c77a21c228c12779de5ac39c686cc08d7b624..926a0f2da341f6fd13780dbc69bc5e088c95e032 100644 (file)
@@ -11,6 +11,7 @@ import (
 
        "git.curoverse.com/arvados.git/sdk/go/arvados"
        "git.curoverse.com/arvados.git/sdk/go/config"
+       "github.com/ghodss/yaml"
 )
 
 const defaultConfigPath = "/etc/arvados/keep-balance/keep-balance.yml"
@@ -78,6 +79,7 @@ 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)")
+       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
@@ -88,6 +90,15 @@ func main() {
                mustReadConfig(&config.KeepServiceList, *serviceListPath)
        }
 
+       if *dumpConfig {
+               y, err := yaml.Marshal(config)
+               if err != nil {
+                       log.Fatal(err)
+               }
+               os.Stdout.Write(y)
+               os.Exit(0)
+       }
+
        if *debugFlag {
                debugf = log.Printf
                if j, err := json.Marshal(config); err != nil {
index df8a0b5c078b31d3a42b51786e3d4f6d0f15477f..cd55355c7ca184439c9eb66a86ad3c55f0bf00b2 100644 (file)
@@ -8,6 +8,7 @@ import (
        "git.curoverse.com/arvados.git/sdk/go/arvados"
        "git.curoverse.com/arvados.git/sdk/go/config"
        "github.com/coreos/go-systemd/daemon"
+       "github.com/ghodss/yaml"
 )
 
 var (
@@ -62,6 +63,8 @@ func main() {
                "Only serve attachments at the given `host:port`"+deprecated)
        flag.BoolVar(&cfg.TrustAllContent, "trust-all-content", false,
                "Serve non-public content from a single origin. Dangerous: read docs before using!"+deprecated)
+       dumpConfig := flag.Bool("dump-config", false,
+               "write current configuration to stdout and exit")
        flag.Usage = usage
        flag.Parse()
 
@@ -78,6 +81,15 @@ func main() {
                cfg.AnonymousTokens = []string{os.Getenv("ARVADOS_API_TOKEN")}
        }
 
+       if *dumpConfig {
+               y, err := yaml.Marshal(cfg)
+               if err != nil {
+                       log.Fatal(err)
+               }
+               os.Stdout.Write(y)
+               os.Exit(0)
+       }
+
        os.Setenv("ARVADOS_API_HOST", cfg.Client.APIHost)
        srv := &server{Config: cfg}
        if err := srv.Start(); err != nil {
index 24df531fa4ab434fea7652503db1d44f1ba04a9b..2376284e1bc495542663dac94067ea0de12dba26 100644 (file)
@@ -1,7 +1,6 @@
 package main
 
 import (
-       "encoding/json"
        "errors"
        "flag"
        "fmt"
@@ -22,6 +21,7 @@ import (
        "git.curoverse.com/arvados.git/sdk/go/config"
        "git.curoverse.com/arvados.git/sdk/go/keepclient"
        "github.com/coreos/go-systemd/daemon"
+       "github.com/ghodss/yaml"
        "github.com/gorilla/mux"
 )
 
@@ -62,6 +62,7 @@ func main() {
        var cfgPath string
        const defaultCfgPath = "/etc/arvados/keepproxy/keepproxy.yml"
        flagset.StringVar(&cfgPath, "config", defaultCfgPath, "Configuration file `path`")
+       dumpConfig := flagset.Bool("dump-config", false, "write current configuration to stdout and exit")
        flagset.Parse(os.Args[1:])
 
        err := config.LoadFile(cfg, cfgPath)
@@ -77,12 +78,21 @@ func main() {
                if regexp.MustCompile("^(?i:1|yes|true)$").MatchString(os.Getenv("ARVADOS_API_HOST_INSECURE")) {
                        cfg.Client.Insecure = true
                }
-               if j, err := json.MarshalIndent(cfg, "", "    "); err == nil {
-                       log.Print("Current configuration:\n", string(j))
+               if y, err := yaml.Marshal(cfg); err == nil && !*dumpConfig {
+                       log.Print("Current configuration:\n", string(y))
                }
                cfg.Timeout = arvados.Duration(time.Duration(*timeoutSeconds) * time.Second)
        }
 
+       if *dumpConfig {
+               y, err := yaml.Marshal(cfg)
+               if err != nil {
+                       log.Fatal(err)
+               }
+               os.Stdout.Write(y)
+               os.Exit(0)
+       }
+
        arv, err := arvadosclient.New(&cfg.Client)
        if err != nil {
                log.Fatalf("Error setting up arvados client %s", err.Error())