Merge branch '2449-keep-write-blocks' into 2449-keep-flags
[arvados.git] / services / keep / keep.go
index 7cca5344d8a2abc074cfb0f0f4dbd66d4fd2f0af..85e2aea5ef2007408cadbfcc1cc555ab6867221e 100644 (file)
@@ -5,6 +5,7 @@ import (
        "bytes"
        "crypto/md5"
        "errors"
+       "flag"
        "fmt"
        "github.com/gorilla/mux"
        "io/ioutil"
@@ -17,8 +18,8 @@ import (
        "time"
 )
 
-// Default TCP port on which to listen for requests.
-const DEFAULT_PORT = 25107
+// Default TCP address on which to listen for requests.
+const DEFAULT_ADDR = ":25107"
 
 // A Keep "block" is 64MB.
 const BLOCKSIZE = 64 * 1024 * 1024
@@ -50,8 +51,21 @@ func (e *KeepError) Error() string {
 }
 
 func main() {
+       // Parse command-line flags.
+       var listen, keepvols string
+       flag.StringVar(&listen, "listen", DEFAULT_ADDR,
+               "interface on which to listen for requests")
+       flag.StringVar(&keepvols, "volumes", "",
+               "comma-separated list of directories to use for Keep volumes")
+       flag.Parse()
+
        // Look for local keep volumes.
-       KeepVolumes = FindKeepVolumes()
+       if keepvols == "" {
+               KeepVolumes = FindKeepVolumes()
+       } else {
+               KeepVolumes = strings.Split(keepvols, ",")
+       }
+
        if len(KeepVolumes) == 0 {
                log.Fatal("could not find any keep volumes")
        }
@@ -73,8 +87,7 @@ func main() {
        http.Handle("/", rest)
 
        // Start listening for requests.
-       port := fmt.Sprintf(":%d", DEFAULT_PORT)
-       http.ListenAndServe(port, nil)
+       http.ListenAndServe(listen, nil)
 }
 
 // FindKeepVolumes