aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/policy/wait_for_port.sh
blob: 58bf25d041de625a146592a863eebb10ca8d7622 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash

if [[ $# -ne 2 ]]; then
	echo "Usage: wait-for-port hostname port" >&2
	exit 1
fi

export host=$1
export port=$2

echo "Waiting for $host port $port open"
timeout 120 bash -c 'until nc -vz "$host" "$port"; do echo -n "."; sleep 1; done'
rc=$?

if [[ $rc != 0 ]]; then
        echo "$host port $port cannot be reached"
        exit $rc
fi

echo "$host port $port is open"
exit 0