From 52ebcc3e6211dc76299bea79b85dce891c6df705 Mon Sep 17 00:00:00 2001 From: mmetc <92726601+mmetc@users.noreply.github.com> Date: Tue, 27 May 2025 15:18:14 +0200 Subject: [PATCH] deprecate option 'daemonize' (#3648) --- cmd/crowdsec/main.go | 16 ++++------------ cmd/crowdsec/serve.go | 2 +- config/config_win.yaml | 1 - config/config_win_no_lapi.yaml | 1 - config/dev.yaml | 1 - config/user.yaml | 1 - docker/config.yaml | 1 - pkg/csconfig/common.go | 6 +++++- pkg/csconfig/config.go | 5 ++--- pkg/csconfig/testdata/config.yaml | 1 - test/bats/40_cold-logs.bats | 2 +- test/lib/config/config-local | 1 - 12 files changed, 13 insertions(+), 25 deletions(-) diff --git a/cmd/crowdsec/main.go b/cmd/crowdsec/main.go index 188116fb2..8bab12e53 100644 --- a/cmd/crowdsec/main.go +++ b/cmd/crowdsec/main.go @@ -144,7 +144,7 @@ func (l *labelsMap) String() string { } func (l *labelsMap) Set(label string) error { - for _, pair := range strings.Split(label, ",") { + for pair := range strings.SplitSeq(label, ",") { split := strings.Split(pair, ":") if len(split) != 2 { return fmt.Errorf("invalid format for label '%s', must be key:value", pair) @@ -233,7 +233,9 @@ func LoadConfig(configFile string, disableAgent bool, disableAPI bool, quiet boo if err := trace.Init(filepath.Join(cConfig.ConfigPaths.DataDir, "trace")); err != nil { return nil, fmt.Errorf("while setting up trace directory: %w", err) } + var logLevelViaFlag bool + cConfig.Common.LogLevel, logLevelViaFlag = newLogLevel(cConfig.Common.LogLevel, flags) if dumpFolder != "" { @@ -301,24 +303,14 @@ func LoadConfig(configFile string, disableAgent bool, disableAPI bool, quiet boo if cConfig.API != nil && cConfig.API.Server != nil { cConfig.API.Server.OnlineClient = nil } - // if the api is disabled as well, just read file and exit, don't daemonize - if cConfig.DisableAPI { - cConfig.Common.Daemonize = false - } - log.Infof("single file mode : log_media=%s daemonize=%t", cConfig.Common.LogMedia, cConfig.Common.Daemonize) + log.Infof("single file mode : log_media=%s", cConfig.Common.LogMedia) } if cConfig.Common.PidDir != "" { log.Warn("Deprecation warning: the pid_dir config can be safely removed and is not required") } - if cConfig.Common.Daemonize && runtime.GOOS == "windows" { - log.Debug("Daemonization is not supported on Windows, disabling") - - cConfig.Common.Daemonize = false - } - // recap of the enabled feature flags, because logging // was not enabled when we set them from envvars if fflist := csconfig.ListFeatureFlags(); fflist != "" { diff --git a/cmd/crowdsec/serve.go b/cmd/crowdsec/serve.go index 642ac46b8..62e128453 100644 --- a/cmd/crowdsec/serve.go +++ b/cmd/crowdsec/serve.go @@ -418,7 +418,7 @@ func Serve(cConfig *csconfig.Config, agentReady chan bool) error { return nil } - if cConfig.Common != nil && cConfig.Common.Daemonize { + if cConfig.Common != nil && !flags.haveTimeMachine() { _ = csdaemon.Notify(csdaemon.Ready, log.StandardLogger()) // wait for signals return HandleSignals(cConfig) diff --git a/config/config_win.yaml b/config/config_win.yaml index 5c34c69a2..7274c04d8 100644 --- a/config/config_win.yaml +++ b/config/config_win.yaml @@ -1,5 +1,4 @@ common: - daemonize: false log_media: file log_level: info log_dir: C:\ProgramData\CrowdSec\log\ diff --git a/config/config_win_no_lapi.yaml b/config/config_win_no_lapi.yaml index af240228b..acc782bdb 100644 --- a/config/config_win_no_lapi.yaml +++ b/config/config_win_no_lapi.yaml @@ -1,5 +1,4 @@ common: - daemonize: true log_media: file log_level: info log_dir: C:\ProgramData\CrowdSec\log\ diff --git a/config/dev.yaml b/config/dev.yaml index ca1f35f32..a124dc540 100644 --- a/config/dev.yaml +++ b/config/dev.yaml @@ -1,5 +1,4 @@ common: - daemonize: true log_media: stdout log_level: info config_paths: diff --git a/config/user.yaml b/config/user.yaml index a1047dcd0..a2fac5ca7 100644 --- a/config/user.yaml +++ b/config/user.yaml @@ -1,5 +1,4 @@ common: - daemonize: false log_media: stdout log_level: info log_dir: /var/log/ diff --git a/docker/config.yaml b/docker/config.yaml index 681132909..9572a573c 100644 --- a/docker/config.yaml +++ b/docker/config.yaml @@ -1,5 +1,4 @@ common: - daemonize: false log_media: stdout log_level: info log_dir: /var/log/ diff --git a/pkg/csconfig/common.go b/pkg/csconfig/common.go index e312756ce..d792928a1 100644 --- a/pkg/csconfig/common.go +++ b/pkg/csconfig/common.go @@ -9,7 +9,7 @@ import ( /*daemonization/service related stuff*/ type CommonCfg struct { - Daemonize bool + Daemonize string // TODO: This is just for backward compat. Remove this later PidDir string `yaml:"pid_dir,omitempty"` // TODO: This is just for backward compat. Remove this later LogMedia string `yaml:"log_media"` LogDir string `yaml:"log_dir,omitempty"` // if LogMedia = file @@ -30,6 +30,10 @@ func (c *Config) loadCommon() error { c.Common = &CommonCfg{} } + if c.Common.Daemonize != "" { + log.Debug("the option 'daemonize' is deprecated and ignored") + } + if c.Common.LogMedia == "" { c.Common.LogMedia = "stdout" } diff --git a/pkg/csconfig/config.go b/pkg/csconfig/config.go index b0784e5e6..8ec356d66 100644 --- a/pkg/csconfig/config.go +++ b/pkg/csconfig/config.go @@ -115,9 +115,8 @@ func GetConfig() Config { func NewDefaultConfig() *Config { logLevel := log.InfoLevel commonCfg := CommonCfg{ - Daemonize: false, - LogMedia: "stdout", - LogLevel: &logLevel, + LogMedia: "stdout", + LogLevel: &logLevel, } prometheus := PrometheusCfg{ Enabled: true, diff --git a/pkg/csconfig/testdata/config.yaml b/pkg/csconfig/testdata/config.yaml index 17975b105..705f5fcc5 100644 --- a/pkg/csconfig/testdata/config.yaml +++ b/pkg/csconfig/testdata/config.yaml @@ -1,5 +1,4 @@ common: - daemonize: false log_media: stdout log_level: info prometheus: diff --git a/test/bats/40_cold-logs.bats b/test/bats/40_cold-logs.bats index 526050542..f3e8cd14f 100644 --- a/test/bats/40_cold-logs.bats +++ b/test/bats/40_cold-logs.bats @@ -40,7 +40,7 @@ setup() { @test "the one-shot mode works" { rune -0 "$CROWDSEC" -dsn file://<(fake_log) -type syslog -no-api refute_output - assert_stderr --partial "single file mode : log_media=stdout daemonize=false" + assert_stderr --partial "single file mode : log_media=stdout" assert_stderr --regexp "Adding file .* to filelist" assert_stderr --regexp "reading .* at once" assert_stderr --partial "Ip 1.1.1.172 performed 'crowdsecurity/ssh-bf' (6 events over 0s)" diff --git a/test/lib/config/config-local b/test/lib/config/config-local index e6588c61c..0acb325b2 100755 --- a/test/lib/config/config-local +++ b/test/lib/config/config-local @@ -77,7 +77,6 @@ config_generate() { "${CONFIG_DIR}/notifications/" yq e ' - .common.daemonize=true | del(.common.pid_dir) | .common.log_level="info" | .common.log_dir=strenv(LOG_DIR) |