Merge branch '14287-controller-structure'
[arvados.git] / lib / service / cmd.go
index cfc40778fefe43d565bb0658b626e899edfc1f09..603f48890eccb6686a77ff8f80e99a8d020bfd52 100644 (file)
@@ -10,7 +10,7 @@ import (
        "flag"
        "fmt"
        "io"
-       "log"
+       "io/ioutil"
        "net"
        "net/http"
        "net/url"
@@ -72,7 +72,10 @@ func (c *command) RunCommand(prog string, args []string, stdin io.Reader, stdout
        } else if err != nil {
                return 2
        }
-       cfg, err := config.LoadFile(*configFile, log)
+       // Logged warnings are discarded for now: the config template
+       // is incomplete, which causes extra warnings about keys that
+       // are really OK.
+       cfg, err := config.LoadFile(*configFile, ctxlog.New(ioutil.Discard, "json", "error"))
        if err != nil {
                return 1
        }
@@ -113,7 +116,8 @@ func (c *command) RunCommand(prog string, args []string, stdin io.Reader, stdout
        }
        srv := &httpserver.Server{
                Server: http.Server{
-                       Handler: httpserver.AddRequestIDs(httpserver.LogRequests(log, handler)),
+                       Handler: httpserver.HandlerWithContext(ctx,
+                               httpserver.AddRequestIDs(httpserver.LogRequests(handler))),
                },
                Addr: listen,
        }
@@ -142,16 +146,7 @@ func (c *command) RunCommand(prog string, args []string, stdin io.Reader, stdout
 const rfc3339NanoFixed = "2006-01-02T15:04:05.000000000Z07:00"
 
 func getListenAddr(svcs arvados.Services, prog arvados.ServiceName) (string, error) {
-       svc, ok := map[arvados.ServiceName]arvados.Service{
-               arvados.ServiceNameController:    svcs.Controller,
-               arvados.ServiceNameDispatchCloud: svcs.DispatchCloud,
-               arvados.ServiceNameHealth:        svcs.Health,
-               arvados.ServiceNameKeepbalance:   svcs.Keepbalance,
-               arvados.ServiceNameKeepproxy:     svcs.Keepproxy,
-               arvados.ServiceNameKeepstore:     svcs.Keepstore,
-               arvados.ServiceNameKeepweb:       svcs.WebDAV,
-               arvados.ServiceNameWebsocket:     svcs.Websocket,
-       }[prog]
+       svc, ok := svcs.Map()[prog]
        if !ok {
                return "", fmt.Errorf("unknown service name %q", prog)
        }
@@ -164,8 +159,6 @@ func getListenAddr(svcs arvados.Services, prog arvados.ServiceName) (string, err
                        listener.Close()
                        return url.Host, nil
                }
-               log.Print(err)
-
        }
        return "", fmt.Errorf("configuration does not enable the %s service on this host", prog)
 }