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