diff --git a/cmd/crowdsec/main.go b/cmd/crowdsec/main.go index f3af9075057..bfbc94f2dee 100644 --- a/cmd/crowdsec/main.go +++ b/cmd/crowdsec/main.go @@ -75,6 +75,10 @@ type Flags struct { CpuProfile string } +func (f *Flags) haveTimeMachine() bool { + return f.OneShotDSN != "" +} + type labelsMap map[string]string func LoadBuckets(cConfig *csconfig.Config, hub *cwhub.Hub) error { @@ -369,8 +373,7 @@ func main() { defer pprof.StopCPUProfile() } - timeMachine := flags.OneShotDSN != "" - err := StartRunSvc(timeMachine) + err := StartRunSvc() if err != nil { pprof.StopCPUProfile() log.Fatal(err) //nolint:gocritic // Disable warning for the defer pprof.StopCPUProfile() call diff --git a/cmd/crowdsec/run_in_svc.go b/cmd/crowdsec/run_in_svc.go index 0c982e87c0f..1d12c8d1167 100644 --- a/cmd/crowdsec/run_in_svc.go +++ b/cmd/crowdsec/run_in_svc.go @@ -15,7 +15,7 @@ import ( "github.com/crowdsecurity/crowdsec/pkg/database" ) -func StartRunSvc(timeMachine bool) error { +func StartRunSvc() error { var ( cConfig *csconfig.Config err error @@ -37,7 +37,7 @@ func StartRunSvc(timeMachine bool) error { agentReady := make(chan bool, 1) // Enable profiling early - if cConfig.Prometheus != nil && !timeMachine { + if cConfig.Prometheus != nil && !flags.haveTimeMachine() { var dbClient *database.Client var err error diff --git a/cmd/crowdsec/run_in_svc_windows.go b/cmd/crowdsec/run_in_svc_windows.go index 2541a67d2fb..aeef58e2fa5 100644 --- a/cmd/crowdsec/run_in_svc_windows.go +++ b/cmd/crowdsec/run_in_svc_windows.go @@ -14,7 +14,7 @@ import ( "github.com/crowdsecurity/crowdsec/pkg/database" ) -func StartRunSvc(timeMachine bool) error { +func StartRunSvc() error { const svcName = "CrowdSec" const svcDescription = "Crowdsec IPS/IDS" @@ -60,7 +60,7 @@ func StartRunSvc(timeMachine bool) error { return nil } -func WindowsRun(timeMachine bool) error { +func WindowsRun() error { var ( cConfig *csconfig.Config err error @@ -77,7 +77,7 @@ func WindowsRun(timeMachine bool) error { agentReady := make(chan bool, 1) // Enable profiling early - if cConfig.Prometheus != nil && !timeMachine { + if cConfig.Prometheus != nil && !flags.haveTimeMachine() { var dbClient *database.Client var err error