crowdsec/tests/bin/assert-crowdsec-not-running
mmetc a0d69783cd
non-fatal error if some datasource can't be run (i.e. journalctl but systemd is missing) (#2310)
This on the other hand, gives a new fatal error when there are no valid datasources.
In the previous version, crowdsec kept running with just a warning if no
acquisition yaml or dir were specified.
2023-06-27 10:46:25 +02:00

26 lines
648 B
Bash
Executable file

#!/usr/bin/env bash
is_crowdsec_running() {
PIDS=$(pgrep -x 'crowdsec|crowdsec.test|crowdsec.cover' 2>/dev/null)
}
# The process can be slow, especially on CI and during test coverage.
# Give it some time, maybe it's quitting soon.
for _i in {1..10}; do
is_crowdsec_running || exit 0
sleep .5
done
PIDS=$(echo "${PIDS}" | tr '\n' ' ')
msg="CrowdSec is already running (PID ${PIDS}). Please terminate it and run the tests again."
# Are we inside a setup() or @test? Is file descriptor 3 open?
if { true >&3; } 2>/dev/null; then
echo "${msg}" >&3
else
echo "${msg}" >&2
fi
# cause the calling setup() or @test to fail
exit 1