diff --git a/daemon/control.go b/daemon/control.go index 9c5e0cb..d71976d 100644 --- a/daemon/control.go +++ b/daemon/control.go @@ -16,6 +16,7 @@ import ( "github.com/zrepl/zrepl/daemon/job" "github.com/zrepl/zrepl/daemon/nethelpers" "github.com/zrepl/zrepl/logger" + "github.com/zrepl/zrepl/util/envconst" "github.com/zrepl/zrepl/version" "github.com/zrepl/zrepl/zfs" ) @@ -86,6 +87,12 @@ func (j *controlJob) Run(ctx context.Context) { } pprofServer := NewPProfServer(ctx) + if listen := envconst.String("ZREPL_DAEMON_AUTOSTART_PPROF_SERVER", ""); listen != "" { + pprofServer.Control(PprofServerControlMsg{ + Run: true, + HttpListenAddress: listen, + }) + } mux := http.NewServeMux() mux.Handle(ControlJobEndpointPProf, diff --git a/util/envconst/envconst.go b/util/envconst/envconst.go index 44bc9b8..5b00a76 100644 --- a/util/envconst/envconst.go +++ b/util/envconst/envconst.go @@ -56,3 +56,15 @@ func Bool(varname string, def bool) bool { cache.Store(varname, d) return d } + +func String(varname string, def string) string { + if v, ok := cache.Load(varname); ok { + return v.(string) + } + e := os.Getenv(varname) + if e == "" { + return def + } + cache.Store(varname, e) + return e +}