crowdsec/tests/assert-crowdsec-not-running

28 lines
674 B
Bash
Executable file

#!/usr/bin/env bash
is_crowdsec_running() {
PIDS=$(pgrep -x 'crowdsec|crowdsec.test|crowdsec.cover')
}
is_crowdsec_running || exit 0
# The process can be slow, especially on CI and during test coverage.
# Give it some time, maybe it's quitting soon.
sleep 2
is_crowdsec_running || exit 0
sleep 2
is_crowdsec_running || exit 0
PIDS=$(echo "$PIDS" | sed ':a;N;$!ba;s/\n/ /g')
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