X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/b8679688545cab79988c568b531d2496fc93cd6e..0f42105b1b59d1b5da764f34e6eb6a1137d7e1cb:/lib/service/cmd.go diff --git a/lib/service/cmd.go b/lib/service/cmd.go index 9ca2431258..880799b348 100644 --- a/lib/service/cmd.go +++ b/lib/service/cmd.go @@ -12,6 +12,7 @@ import ( "io" "net" "net/http" + _ "net/http/pprof" "net/url" "os" "strings" @@ -70,16 +71,19 @@ func (c *command) RunCommand(prog string, args []string, stdin io.Reader, stdout loader := config.NewLoader(stdin, log) loader.SetupFlags(flags) versionFlag := flags.Bool("version", false, "Write version information to stdout and exit 0") - err = flags.Parse(args) - if err == flag.ErrHelp { - err = nil - return 0 - } else if err != nil { - return 2 + pprofAddr := flags.String("pprof", "", "Serve Go profile data at `[addr]:port`") + if ok, code := cmd.ParseFlags(flags, prog, args, "", stderr); !ok { + return code } else if *versionFlag { return cmd.Version.RunCommand(prog, args, stdin, stdout, stderr) } + if *pprofAddr != "" { + go func() { + log.Println(http.ListenAndServe(*pprofAddr, nil)) + }() + } + if strings.HasSuffix(prog, "controller") { // Some config-loader checks try to make API calls via // controller. Those can't be expected to work if this @@ -118,13 +122,14 @@ func (c *command) RunCommand(prog string, args []string, stdin io.Reader, stdout } instrumented := httpserver.Instrument(reg, log, - httpserver.HandlerWithContext(ctx, + httpserver.HandlerWithDeadline(cluster.API.RequestTimeout.Duration(), httpserver.AddRequestIDs( httpserver.LogRequests( httpserver.NewRequestLimiter(cluster.API.MaxConcurrentRequests, handler, reg))))) srv := &httpserver.Server{ Server: http.Server{ - Handler: instrumented.ServeAPI(cluster.ManagementToken, instrumented), + Handler: instrumented.ServeAPI(cluster.ManagementToken, instrumented), + BaseContext: func(net.Listener) context.Context { return ctx }, }, Addr: listenURL.Host, }