2022-03-09 13:45:36 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2022-04-05 09:00:11 +00:00
|
|
|
is_crowdsec_running() {
|
2023-06-29 14:35:19 +00:00
|
|
|
case $(uname) in
|
|
|
|
"Linux")
|
|
|
|
# ignore processes in containers
|
|
|
|
PIDS=$(pgrep --ns $$ -x 'crowdsec')
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
PIDS=$(pgrep -x 'crowdsec')
|
|
|
|
;;
|
|
|
|
esac
|
2022-04-05 09:00:11 +00:00
|
|
|
}
|
2022-03-09 13:45:36 +00:00
|
|
|
|
2022-04-05 09:00:11 +00:00
|
|
|
# The process can be slow, especially on CI and during test coverage.
|
|
|
|
# Give it some time, maybe it's quitting soon.
|
2022-08-04 09:25:34 +00:00
|
|
|
for _i in {1..10}; do
|
|
|
|
is_crowdsec_running || exit 0
|
|
|
|
sleep .5
|
|
|
|
done
|
2022-03-09 13:45:36 +00:00
|
|
|
|
2022-06-22 08:00:51 +00:00
|
|
|
PIDS=$(echo "${PIDS}" | tr '\n' ' ')
|
2022-06-13 19:54:47 +00:00
|
|
|
msg="CrowdSec is already running (PID ${PIDS}). Please terminate it and run the tests again."
|
2022-03-09 13:45:36 +00:00
|
|
|
|
|
|
|
# Are we inside a setup() or @test? Is file descriptor 3 open?
|
|
|
|
if { true >&3; } 2>/dev/null; then
|
2022-06-13 19:54:47 +00:00
|
|
|
echo "${msg}" >&3
|
2022-03-09 13:45:36 +00:00
|
|
|
else
|
2022-06-13 19:54:47 +00:00
|
|
|
echo "${msg}" >&2
|
2022-03-09 13:45:36 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# cause the calling setup() or @test to fail
|
|
|
|
exit 1
|