我有这个脚本来检查网络服务器是否启动并且健康检查是否成功。我在服务开始之前使用“睡眠”。我正在寻求改进它,并放置一些“迭代/直到”选项来检查服务健康检查是否成功,但会超时 60/120 秒并进行 LB 注册,否则会引发错误。
#!/bin/bash
instanceid=$(wget -q -O - http://169.254.169.254/latest/meta-data/instance-id)
healthcheck=$(curl -X GET http://localhost | grep "yes its working")
HEALTHCHECK=$?
if [ $HEALTHCHECK -eq 0 ] ; then
echo "Server registered to ELB"
usr/local/bin/aws elbv2 register-targets --target-group-arn arn:aws:elasticloadbalancing:ap-south-1:xxxxxxxx:targetgroup/my-targetgroup/xxxxxxxx --targets Id=$instanceid
exit 0
else
echo "healthcheck failed"
exit 0
fi