Fix: subcommand not recognized in $0 when no CLI args are given.
[arvados.git] / services / keep-balance / main.go
index ecc3f2696f6ab2ef29b4ece9d3071dd75c91389b..90235cbf3188d91bc274412ddd5522dc639fa812 100644 (file)
@@ -9,6 +9,7 @@ import (
        "flag"
        "fmt"
        "log"
+       "net/http"
        "os"
        "os/signal"
        "syscall"
@@ -45,6 +46,9 @@ type Config struct {
        // more memory, but can reduce store-and-forward latency when
        // fetching pages)
        CollectionBuffers int
+
+       // Timeout for outgoing http request/response cycle.
+       RequestTimeout arvados.Duration
 }
 
 // RunOptions controls runtime behavior. The flags/options that belong
@@ -94,8 +98,8 @@ func main() {
 
        // Print version information if requested
        if *getVersion {
-               fmt.Printf("Version: %s\n", version)
-               os.Exit(0)
+               fmt.Printf("keep-balance %s\n", version)
+               return
        }
 
        mustReadConfig(&cfg, *configPath)
@@ -107,7 +111,15 @@ func main() {
                log.Fatal(config.DumpAndExit(cfg))
        }
 
-       log.Printf("keep-balance %q started", version)
+       to := time.Duration(cfg.RequestTimeout)
+       if to == 0 {
+               to = 30 * time.Minute
+       }
+       arvados.DefaultSecureClient.Timeout = to
+       arvados.InsecureHTTPClient.Timeout = to
+       http.DefaultClient.Timeout = to
+
+       log.Printf("keep-balance %s started", version)
 
        if *debugFlag {
                debugf = log.Printf