storj/pkg/process/debug.go

46 lines
870 B
Go
Raw Normal View History

2019-01-24 20:15:10 +00:00
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package process
import (
"context"
"flag"
"fmt"
"net"
"github.com/spacemonkeygo/monkit/v3"
"go.uber.org/zap"
"storj.io/storj/pkg/debug"
)
var (
// DebugAddrFlag for --debug.addr
DebugAddrFlag = flag.String("debug.addr", "127.0.0.1:0", "address to listen on for debug endpoints")
)
func initDebug(log *zap.Logger, r *monkit.Registry) (err error) {
if *DebugAddrFlag == "" {
return nil
2019-07-03 15:10:51 +01:00
}
ln, err := net.Listen("tcp", *DebugAddrFlag)
if err != nil {
return err
}
go func() {
server := debug.NewServer(log, ln, r, debug.Config{
Address: *DebugAddrFlag,
})
log.Debug(fmt.Sprintf("debug server listening on %s", ln.Addr().String()))
err := server.Run(context.TODO())
if err != nil {
log.Error("debug server died", zap.Error(err))
}
}()
return nil
}