From 76e97303a566d06a88029dd0fb44cc531bd2597f Mon Sep 17 00:00:00 2001 From: Shivam Sandbhor Date: Wed, 16 Mar 2022 13:53:49 +0530 Subject: [PATCH] Deprecate pid_file config (#1346) * Deprecate pid_file config Signed-off-by: Shivam Sandbhor * Fix unit test Signed-off-by: Shivam Sandbhor * Impl review suggestions. Signed-off-by: Shivam Sandbhor --- cmd/crowdsec/main.go | 4 ++++ config/crowdsec.service | 1 - debian/crowdsec.service | 1 - pkg/csconfig/common.go | 3 +-- pkg/csconfig/common_test.go | 10 +++------- rpm/SOURCES/crowdsec.unit.patch | 2 -- wizard.sh | 6 ++---- 7 files changed, 10 insertions(+), 17 deletions(-) diff --git a/cmd/crowdsec/main.go b/cmd/crowdsec/main.go index d8c68c0f3..d0e8f57fa 100644 --- a/cmd/crowdsec/main.go +++ b/cmd/crowdsec/main.go @@ -251,6 +251,10 @@ func LoadConfig(cConfig *csconfig.Config) error { log.Infof("single file mode : log_media=%s daemonize=%t", cConfig.Common.LogMedia, cConfig.Common.Daemonize) } + if cConfig.Common.PidDir != "" { + log.Warn("Deprecation warning: the pid_dir config can be safely removed and is not required") + } + return nil } diff --git a/config/crowdsec.service b/config/crowdsec.service index 4afa74d8c..4b6c26fce 100644 --- a/config/crowdsec.service +++ b/config/crowdsec.service @@ -5,7 +5,6 @@ After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type=notify Environment=LC_ALL=C LANG=C -PIDFile=/var/run/crowdsec.pid ExecStartPre=/usr/local/bin/crowdsec -c /etc/crowdsec/config.yaml -t ExecStart=/usr/local/bin/crowdsec -c /etc/crowdsec/config.yaml #ExecStartPost=/bin/sleep 0.1 diff --git a/debian/crowdsec.service b/debian/crowdsec.service index 839da0d96..8743a03bc 100644 --- a/debian/crowdsec.service +++ b/debian/crowdsec.service @@ -5,7 +5,6 @@ After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type=notify Environment=LC_ALL=C LANG=C -PIDFile=/run/crowdsec.pid ExecStartPre=/usr/bin/crowdsec -c /etc/crowdsec/config.yaml -t ExecStart=/usr/bin/crowdsec -c /etc/crowdsec/config.yaml #ExecStartPost=/bin/sleep 0.1 diff --git a/pkg/csconfig/common.go b/pkg/csconfig/common.go index 4f53e08d6..79a67a155 100644 --- a/pkg/csconfig/common.go +++ b/pkg/csconfig/common.go @@ -11,7 +11,7 @@ import ( /*daemonization/service related stuff*/ type CommonCfg struct { Daemonize bool - PidDir string `yaml:"pid_dir"` + 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 LogLevel *log.Level `yaml:"log_level"` @@ -29,7 +29,6 @@ func (c *Config) LoadCommon() error { } var CommonCleanup = []*string{ - &c.Common.PidDir, &c.Common.LogDir, &c.Common.WorkingDir, } diff --git a/pkg/csconfig/common_test.go b/pkg/csconfig/common_test.go index 6133fc0b8..b049a8220 100644 --- a/pkg/csconfig/common_test.go +++ b/pkg/csconfig/common_test.go @@ -10,11 +10,7 @@ import ( ) func TestLoadCommon(t *testing.T) { - PidDirFullPath, err := filepath.Abs("./tests/") - if err != nil { - t.Fatalf(err.Error()) - } - + pidDirPath := "./tests" LogDirFullPath, err := filepath.Abs("./tests/log/") if err != nil { t.Fatalf(err.Error()) @@ -44,7 +40,7 @@ func TestLoadCommon(t *testing.T) { }, expectedResult: &CommonCfg{ Daemonize: true, - PidDir: PidDirFullPath, + PidDir: pidDirPath, LogMedia: "file", LogDir: LogDirFullPath, WorkingDir: WorkingDirFullPath, @@ -62,7 +58,7 @@ func TestLoadCommon(t *testing.T) { }, expectedResult: &CommonCfg{ Daemonize: true, - PidDir: PidDirFullPath, + PidDir: pidDirPath, LogMedia: "file", LogDir: LogDirFullPath, }, diff --git a/rpm/SOURCES/crowdsec.unit.patch b/rpm/SOURCES/crowdsec.unit.patch index 74635ac48..50ba7858e 100644 --- a/rpm/SOURCES/crowdsec.unit.patch +++ b/rpm/SOURCES/crowdsec.unit.patch @@ -4,10 +4,8 @@ [Service] Type=notify Environment=LC_ALL=C LANG=C --PIDFile=/var/run/crowdsec.pid -ExecStartPre=/usr/local/bin/crowdsec -c /etc/crowdsec/config.yaml -t -ExecStart=/usr/local/bin/crowdsec -c /etc/crowdsec/config.yaml -+PIDFile=/run/crowdsec.pid +ExecStartPre=/usr//bin/crowdsec -c /etc/crowdsec/config.yaml -t +ExecStart=/usr/bin/crowdsec -c /etc/crowdsec/config.yaml #ExecStartPost=/bin/sleep 0.1 diff --git a/wizard.sh b/wizard.sh index e63cf59e3..7e2238009 100755 --- a/wizard.sh +++ b/wizard.sh @@ -46,7 +46,6 @@ ACQUIS_PATH="${CROWDSEC_CONFIG_PATH}" TMP_ACQUIS_FILE="tmp-acquis.yaml" ACQUIS_TARGET="${ACQUIS_PATH}/acquis.yaml" -PID_DIR="${CROWDSEC_RUN_DIR}" SYSTEMD_PATH_FILE="/etc/systemd/system/crowdsec.service" PATTERNS_FOLDER="config/patterns" @@ -410,10 +409,9 @@ install_crowdsec() { install -v -m 644 -D ./config/simulation.yaml "${CROWDSEC_CONFIG_PATH}" 1> /dev/null || exit install -v -m 644 -D ./config/"${CONSOLE_FILE}" "${CROWDSEC_CONFIG_PATH}" 1> /dev/null || exit - mkdir -p ${PID_DIR} || exit - PID=${PID_DIR} DATA=${CROWDSEC_DATA_DIR} CFG=${CROWDSEC_CONFIG_PATH} envsubst '$CFG $PID $DATA' < ./config/user.yaml > ${CROWDSEC_CONFIG_PATH}"/user.yaml" || log_fatal "unable to generate user configuration file" + DATA=${CROWDSEC_DATA_DIR} CFG=${CROWDSEC_CONFIG_PATH} envsubst '$CFG $DATA' < ./config/user.yaml > ${CROWDSEC_CONFIG_PATH}"/user.yaml" || log_fatal "unable to generate user configuration file" if [[ ${DOCKER_MODE} == "false" ]]; then - CFG=${CROWDSEC_CONFIG_PATH} PID=${PID_DIR} BIN=${CROWDSEC_BIN_INSTALLED} envsubst '$CFG $PID $BIN' < ./config/crowdsec.service > "${SYSTEMD_PATH_FILE}" || log_fatal "unable to crowdsec systemd file" + CFG=${CROWDSEC_CONFIG_PATH} BIN=${CROWDSEC_BIN_INSTALLED} envsubst '$CFG $BIN' < ./config/crowdsec.service > "${SYSTEMD_PATH_FILE}" || log_fatal "unable to crowdsec systemd file" fi install_bins