Deprecate pid_file config (#1346)
* Deprecate pid_file config Signed-off-by: Shivam Sandbhor <shivam.sandbhor@gmail.com> * Fix unit test Signed-off-by: Shivam Sandbhor <shivam.sandbhor@gmail.com> * Impl review suggestions. Signed-off-by: Shivam Sandbhor <shivam.sandbhor@gmail.com>
This commit is contained in:
parent
548b0b5518
commit
76e97303a5
7 changed files with 10 additions and 17 deletions
|
@ -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)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ After=syslog.target network.target remote-fs.target nss-lookup.target
|
||||||
[Service]
|
[Service]
|
||||||
Type=notify
|
Type=notify
|
||||||
Environment=LC_ALL=C LANG=C
|
Environment=LC_ALL=C LANG=C
|
||||||
PIDFile=/var/run/crowdsec.pid
|
|
||||||
ExecStartPre=/usr/local/bin/crowdsec -c /etc/crowdsec/config.yaml -t
|
ExecStartPre=/usr/local/bin/crowdsec -c /etc/crowdsec/config.yaml -t
|
||||||
ExecStart=/usr/local/bin/crowdsec -c /etc/crowdsec/config.yaml
|
ExecStart=/usr/local/bin/crowdsec -c /etc/crowdsec/config.yaml
|
||||||
#ExecStartPost=/bin/sleep 0.1
|
#ExecStartPost=/bin/sleep 0.1
|
||||||
|
|
1
debian/crowdsec.service
vendored
1
debian/crowdsec.service
vendored
|
@ -5,7 +5,6 @@ After=syslog.target network.target remote-fs.target nss-lookup.target
|
||||||
[Service]
|
[Service]
|
||||||
Type=notify
|
Type=notify
|
||||||
Environment=LC_ALL=C LANG=C
|
Environment=LC_ALL=C LANG=C
|
||||||
PIDFile=/run/crowdsec.pid
|
|
||||||
ExecStartPre=/usr/bin/crowdsec -c /etc/crowdsec/config.yaml -t
|
ExecStartPre=/usr/bin/crowdsec -c /etc/crowdsec/config.yaml -t
|
||||||
ExecStart=/usr/bin/crowdsec -c /etc/crowdsec/config.yaml
|
ExecStart=/usr/bin/crowdsec -c /etc/crowdsec/config.yaml
|
||||||
#ExecStartPost=/bin/sleep 0.1
|
#ExecStartPost=/bin/sleep 0.1
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
/*daemonization/service related stuff*/
|
/*daemonization/service related stuff*/
|
||||||
type CommonCfg struct {
|
type CommonCfg struct {
|
||||||
Daemonize bool
|
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"`
|
LogMedia string `yaml:"log_media"`
|
||||||
LogDir string `yaml:"log_dir,omitempty"` //if LogMedia = file
|
LogDir string `yaml:"log_dir,omitempty"` //if LogMedia = file
|
||||||
LogLevel *log.Level `yaml:"log_level"`
|
LogLevel *log.Level `yaml:"log_level"`
|
||||||
|
@ -29,7 +29,6 @@ func (c *Config) LoadCommon() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
var CommonCleanup = []*string{
|
var CommonCleanup = []*string{
|
||||||
&c.Common.PidDir,
|
|
||||||
&c.Common.LogDir,
|
&c.Common.LogDir,
|
||||||
&c.Common.WorkingDir,
|
&c.Common.WorkingDir,
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,11 +10,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLoadCommon(t *testing.T) {
|
func TestLoadCommon(t *testing.T) {
|
||||||
PidDirFullPath, err := filepath.Abs("./tests/")
|
pidDirPath := "./tests"
|
||||||
if err != nil {
|
|
||||||
t.Fatalf(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
LogDirFullPath, err := filepath.Abs("./tests/log/")
|
LogDirFullPath, err := filepath.Abs("./tests/log/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf(err.Error())
|
t.Fatalf(err.Error())
|
||||||
|
@ -44,7 +40,7 @@ func TestLoadCommon(t *testing.T) {
|
||||||
},
|
},
|
||||||
expectedResult: &CommonCfg{
|
expectedResult: &CommonCfg{
|
||||||
Daemonize: true,
|
Daemonize: true,
|
||||||
PidDir: PidDirFullPath,
|
PidDir: pidDirPath,
|
||||||
LogMedia: "file",
|
LogMedia: "file",
|
||||||
LogDir: LogDirFullPath,
|
LogDir: LogDirFullPath,
|
||||||
WorkingDir: WorkingDirFullPath,
|
WorkingDir: WorkingDirFullPath,
|
||||||
|
@ -62,7 +58,7 @@ func TestLoadCommon(t *testing.T) {
|
||||||
},
|
},
|
||||||
expectedResult: &CommonCfg{
|
expectedResult: &CommonCfg{
|
||||||
Daemonize: true,
|
Daemonize: true,
|
||||||
PidDir: PidDirFullPath,
|
PidDir: pidDirPath,
|
||||||
LogMedia: "file",
|
LogMedia: "file",
|
||||||
LogDir: LogDirFullPath,
|
LogDir: LogDirFullPath,
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,10 +4,8 @@
|
||||||
[Service]
|
[Service]
|
||||||
Type=notify
|
Type=notify
|
||||||
Environment=LC_ALL=C LANG=C
|
Environment=LC_ALL=C LANG=C
|
||||||
-PIDFile=/var/run/crowdsec.pid
|
|
||||||
-ExecStartPre=/usr/local/bin/crowdsec -c /etc/crowdsec/config.yaml -t
|
-ExecStartPre=/usr/local/bin/crowdsec -c /etc/crowdsec/config.yaml -t
|
||||||
-ExecStart=/usr/local/bin/crowdsec -c /etc/crowdsec/config.yaml
|
-ExecStart=/usr/local/bin/crowdsec -c /etc/crowdsec/config.yaml
|
||||||
+PIDFile=/run/crowdsec.pid
|
|
||||||
+ExecStartPre=/usr//bin/crowdsec -c /etc/crowdsec/config.yaml -t
|
+ExecStartPre=/usr//bin/crowdsec -c /etc/crowdsec/config.yaml -t
|
||||||
+ExecStart=/usr/bin/crowdsec -c /etc/crowdsec/config.yaml
|
+ExecStart=/usr/bin/crowdsec -c /etc/crowdsec/config.yaml
|
||||||
#ExecStartPost=/bin/sleep 0.1
|
#ExecStartPost=/bin/sleep 0.1
|
||||||
|
|
|
@ -46,7 +46,6 @@ ACQUIS_PATH="${CROWDSEC_CONFIG_PATH}"
|
||||||
TMP_ACQUIS_FILE="tmp-acquis.yaml"
|
TMP_ACQUIS_FILE="tmp-acquis.yaml"
|
||||||
ACQUIS_TARGET="${ACQUIS_PATH}/acquis.yaml"
|
ACQUIS_TARGET="${ACQUIS_PATH}/acquis.yaml"
|
||||||
|
|
||||||
PID_DIR="${CROWDSEC_RUN_DIR}"
|
|
||||||
SYSTEMD_PATH_FILE="/etc/systemd/system/crowdsec.service"
|
SYSTEMD_PATH_FILE="/etc/systemd/system/crowdsec.service"
|
||||||
|
|
||||||
PATTERNS_FOLDER="config/patterns"
|
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/simulation.yaml "${CROWDSEC_CONFIG_PATH}" 1> /dev/null || exit
|
||||||
install -v -m 644 -D ./config/"${CONSOLE_FILE}" "${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
|
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"
|
||||||
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"
|
|
||||||
if [[ ${DOCKER_MODE} == "false" ]]; then
|
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
|
fi
|
||||||
install_bins
|
install_bins
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue