crowdsec/tests/lib/util/wait-for-port
Manuel Sabban 16b9fd82f0
Update bats tests to work with systemd (#1394)
* update for making it work with systemd
* take DB_BACKEND from file name; reduce duplicated code; configure db_type=sqlite
* define PACKAGE_TESTING

Co-authored-by: sabban <15465465+sabban@users.noreply.github.com>
Co-authored-by: mmetc <92726601+mmetc@users.noreply.github.com>
2022-03-29 17:06:49 +02:00

32 lines
458 B
Bash
Executable file

#!/usr/bin/env bash
set -eu
script_name=$0
die() {
echo >&2 "$@"
exit 1
}
about() {
die "usage: $script_name <port_number>"
}
[ $# -lt 1 ] && about
port_number=$1
for _ in $(seq 40); do
nc -z localhost "$port_number" >/dev/null 2>&1 && exit 0
sleep .05
done
# send to &3 if open
if { true >&3; } 2>/dev/null; then
echo "Can't connect to port $port_number" >&3
else
echo "Can't connect to port $port_number" >&2
fi
exit 1