10666: Added version number to go sdk and go tools & services
[arvados.git] / services / keepstore / keepstore.go
index 54147959719183141a8e3137d5d1363ec9667e6b..23af6906bbcf89ec0832e8416a3198096edbef1c 100644 (file)
@@ -1,3 +1,7 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
 package main
 
 import (
@@ -14,9 +18,9 @@ import (
        "git.curoverse.com/arvados.git/sdk/go/config"
        "git.curoverse.com/arvados.git/sdk/go/httpserver"
        "git.curoverse.com/arvados.git/sdk/go/keepclient"
+       arvadosVersion "git.curoverse.com/arvados.git/sdk/go/version"
        log "github.com/Sirupsen/logrus"
        "github.com/coreos/go-systemd/daemon"
-       "github.com/ghodss/yaml"
 )
 
 // A Keep "block" is 64MB.
@@ -86,6 +90,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 +102,12 @@ func main() {
        flag.Usage = usage
        flag.Parse()
 
+       // Print version information if requested
+       if *getVersion {
+               fmt.Printf("Version: %s\n", arvadosVersion.GetVersion())
+               os.Exit(0)
+       }
+
        deprecated.afterFlagParse(theConfig)
 
        err := config.LoadFile(theConfig, configPath)
@@ -105,14 +116,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 %q started", arvadosVersion.GetVersion())
+
        err = theConfig.Start()
        if err != nil {
                log.Fatal(err)
@@ -165,7 +173,6 @@ func main() {
        keepClient := &keepclient.KeepClient{
                Arvados:       &arvadosclient.ArvadosClient{},
                Want_replicas: 1,
-               Client:        &http.Client{},
        }
 
        // Initialize the pullq and worker