2017-01-24 11:19:44 +01:00
|
|
|
#!/bin/bash
|
|
|
|
set -exo pipefail
|
|
|
|
|
|
|
|
docker_image=$1
|
|
|
|
port=$2
|
|
|
|
|
2017-07-07 07:26:11 +02:00
|
|
|
container_id=''
|
|
|
|
|
2017-01-24 11:19:44 +01:00
|
|
|
wait_start() {
|
|
|
|
for in in {1..10}; do
|
2017-07-07 07:26:11 +02:00
|
|
|
if /usr/bin/curl -s -m 5 -f "http://localhost:${port}/metrics" > /dev/null; then
|
|
|
|
docker_cleanup
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
sleep 1
|
|
|
|
fi
|
2017-01-24 11:19:44 +01:00
|
|
|
done
|
|
|
|
|
2017-07-07 07:26:11 +02:00
|
|
|
exit 1
|
2017-01-24 11:19:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
docker_start() {
|
2017-07-07 07:26:11 +02:00
|
|
|
container_id=$(docker run -d -p "${port}":"${port}" "${docker_image}")
|
|
|
|
}
|
|
|
|
|
|
|
|
docker_cleanup() {
|
|
|
|
docker kill "${container_id}"
|
2017-01-24 11:19:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if [[ "$#" -ne 2 ]] ; then
|
|
|
|
echo "Usage: $0 quay.io/prometheus/node-exporter:v0.13.0 9100" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
docker_start
|
|
|
|
wait_start
|