sonic-buildimage/dockers/docker-fpm-frr/zsocket.sh
Shi Su aab37b7f42
[FRR] Create a separate script to wait zebra to be ready to receive connections (#6519)
The requirement for zebra to be ready to accept connections is a generic problem that is not 
specific to bgpd. Making the script to wait for zebra socket a separate script and let bgpd and 
staticd to wait for zebra socket.
2021-01-27 12:36:02 -08:00

37 lines
818 B
Bash
Executable File

#!/usr/bin/env bash
addr="127.0.0.1"
port=2601
function help()
{
echo "This script aims to ensure zebra is ready to accept connections"
echo "Usage: $0 [options]"
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
start=$(date +%s.%N)
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"
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"
fi
exit 0