github.com/crowdsecurity/crowdsec@v1.6.1/test/bin/assert-crowdsec-not-running (about) 1 #!/usr/bin/env bash 2 3 is_crowdsec_running() { 4 case $(uname) in 5 "Linux") 6 # ignore processes in containers 7 PIDS=$(pgrep --ns $$ -x 'crowdsec') 8 ;; 9 *) 10 PIDS=$(pgrep -x 'crowdsec') 11 ;; 12 esac 13 } 14 15 # The process can be slow, especially on CI and during test coverage. 16 # Give it some time, maybe it's quitting soon. 17 for _i in {1..10}; do 18 is_crowdsec_running || exit 0 19 sleep .5 20 done 21 22 PIDS=$(echo "${PIDS}" | tr '\n' ' ') 23 msg="CrowdSec is already running (PID ${PIDS}). Please terminate it and run the tests again." 24 25 # Are we inside a setup() or @test? Is file descriptor 3 open? 26 if { true >&3; } 2>/dev/null; then 27 echo "${msg}" >&3 28 else 29 echo "${msg}" >&2 30 fi 31 32 # cause the calling setup() or @test to fail 33 exit 1