10666: Merge branch 'master' into 10666-report-version
[arvados.git] / services / keepstore / keepstore.go
index 54147959719183141a8e3137d5d1363ec9667e6b..b8a0ffb1cba46777ff1e2d1c745eb8102ea5fa61 100644 (file)
@@ -1,3 +1,7 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
 package main
 
 import (
@@ -16,9 +20,10 @@ import (
        "git.curoverse.com/arvados.git/sdk/go/keepclient"
        log "github.com/Sirupsen/logrus"
        "github.com/coreos/go-systemd/daemon"
-       "github.com/ghodss/yaml"
 )
 
+var version = "dev"
+
 // A Keep "block" is 64MB.
 const BlockSize = 64 * 1024 * 1024
 
@@ -86,6 +91,7 @@ func main() {
        deprecated.beforeFlagParse(theConfig)
 
        dumpConfig := flag.Bool("dump-config", false, "write current configuration to stdout and exit (useful for migrating from command line flags to config file)")
+       getVersion := flag.Bool("version", false, "Print version information and exit.")
 
        defaultConfigPath := "/etc/arvados/keepstore/keepstore.yml"
        var configPath string
@@ -97,6 +103,12 @@ func main() {
        flag.Usage = usage
        flag.Parse()
 
+       // Print version information if requested
+       if *getVersion {
+               fmt.Printf("keepstore %s\n", version)
+               return
+       }
+
        deprecated.afterFlagParse(theConfig)
 
        err := config.LoadFile(theConfig, configPath)
@@ -105,14 +117,11 @@ func main() {
        }
 
        if *dumpConfig {
-               y, err := yaml.Marshal(theConfig)
-               if err != nil {
-                       log.Fatal(err)
-               }
-               os.Stdout.Write(y)
-               os.Exit(0)
+               log.Fatal(config.DumpAndExit(theConfig))
        }
 
+       log.Printf("keepstore %s started", version)
+
        err = theConfig.Start()
        if err != nil {
                log.Fatal(err)
@@ -149,11 +158,11 @@ func main() {
        // Start a round-robin VolumeManager with the volumes we have found.
        KeepVM = MakeRRVolumeManager(theConfig.Volumes)
 
-       // Middleware stack: logger, MaxRequests limiter, method handlers
+       // Middleware/handler stack
        router := MakeRESTRouter()
        limiter := httpserver.NewRequestLimiter(theConfig.MaxRequests, router)
        router.limiter = limiter
-       http.Handle("/", &LoggingRESTRouter{router: limiter})
+       http.Handle("/", httpserver.AddRequestIDs(httpserver.LogRequests(limiter)))
 
        // Set up a TCP listener.
        listener, err := net.Listen("tcp", theConfig.Listen)
@@ -165,7 +174,6 @@ func main() {
        keepClient := &keepclient.KeepClient{
                Arvados:       &arvadosclient.ArvadosClient{},
                Want_replicas: 1,
-               Client:        &http.Client{},
        }
 
        // Initialize the pullq and worker