mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-18 15:24:25 +02:00
fix reload issue by returning new configuration to the signal loop example: run crowdsec, disable agent in the config file, reload config. Now there is no agent but the signal loop believes there is, so triggering a reload configuration again will make the process hang forever. This commit updates the configuration in the signal loop with the one returned by the signal handler.
49 lines
1.5 KiB
Bash
Executable file
49 lines
1.5 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
set -eu
|
|
|
|
#
|
|
# Delegate operations to an instrumented binary and collects coverage data.
|
|
#
|
|
|
|
#shellcheck disable=SC1007
|
|
THIS_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
|
# no need to change directory, and doing it here would break hub tests
|
|
# shellcheck disable=SC1091
|
|
. "${THIS_DIR}/../.environment.sh"
|
|
|
|
set -o pipefail # don't let sed hide the statuscode
|
|
mkdir -p "${LOCAL_DIR}/var/lib/coverage"
|
|
|
|
# this would be nice but doesn't work, since the binary is not running in background
|
|
#_hup() {
|
|
# echo "killall -1 crowdsec.cover"
|
|
# killall -HUP crowdsec.cover
|
|
#}
|
|
#
|
|
## relay the "configuration reload" signal
|
|
#trap _hup SIGHUP
|
|
|
|
# we collect rc and output by hand, because setting -o pipefail would trigger a
|
|
# SIGPIPE.
|
|
set +e
|
|
|
|
# Arguments to crowdsec are passed through a temporary, newline-delimited
|
|
# file courtesy of github.com/confluentinc/bincover. Coverage data will be
|
|
# merged at the end of the test run.
|
|
# The '=' between flags and values is required.
|
|
output=$("${BIN_DIR}/crowdsec.cover" \
|
|
-test.run="^TestBincoverRunMain$" \
|
|
-test.coverprofile="${LOCAL_DIR}/var/lib/coverage/crowdsec-$(date +'%s')-$$-${RANDOM}.out" \
|
|
-args-file=<(for i; do echo "${i}"; done))
|
|
rc=$?
|
|
|
|
# If there is bincover metadata, we take the status code from there. Otherwise,
|
|
# we keep the status from the above command.
|
|
if [[ ${output} =~ (.*)(START_BINCOVER_METADATA[[:space:]]*)(.*)([[:space:]]END_BINCOVER_METADATA) ]]; then
|
|
echo -n "${BASH_REMATCH[1]}"
|
|
exit "$(jq '.exit_code' <<< "${BASH_REMATCH[3]}")"
|
|
fi
|
|
|
|
echo -n "${output}"
|
|
exit "${rc}"
|