2021-01-19 02:23:36 -06:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
addr="127.0.0.1"
|
|
|
|
port=2601
|
|
|
|
|
|
|
|
function help()
|
|
|
|
{
|
2021-01-27 14:36:02 -06:00
|
|
|
echo "This script aims to ensure zebra is ready to accept connections"
|
|
|
|
echo "Usage: $0 [options]"
|
2021-01-19 02:23:36 -06:00
|
|
|
echo "Options:"
|
|
|
|
echo " -a Zebra address"
|
|
|
|
echo " -o Zebra port"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
while getopts ":a:o:h" opt; do
|
|
|
|
case "${opt}" in
|
|
|
|
h) help
|
|
|
|
;;
|
|
|
|
a) addr=${OPTARG}
|
|
|
|
;;
|
|
|
|
o) port=${OPTARG}
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2021-01-27 14:36:02 -06:00
|
|
|
start=$(date +%s.%N)
|
2021-01-19 02:23:36 -06:00
|
|
|
timeout 5s bash -c -- "until </dev/tcp/${addr}/${port}; do sleep 0.1;done"
|
|
|
|
if [ "$?" != "0" ]; then
|
|
|
|
logger -p error "Error: zebra is not ready to accept connections"
|
2021-01-27 14:36:02 -06:00
|
|
|
else
|
|
|
|
timespan=$(awk "BEGIN {print $(date +%s.%N)-$start; exit}")
|
|
|
|
logger -p info "It took ${timespan} seconds to wait for zebra to be ready to accept connections"
|
2021-01-19 02:23:36 -06:00
|
|
|
fi
|
|
|
|
|
2021-01-27 14:36:02 -06:00
|
|
|
exit 0
|