我正在使用AWS Opsworks
在AWS上部署应用程序。我已经在脚本中实现了部署自动化,只要部署尚未在Opsworks
完成,我就希望我的任务能够完成。
我使用命令deployment-successful
来执行此操作,但如果部署尚未完成,则会在10分钟后退出255
。有时我们的Opsworks
部署持续时间超过10分钟。在这种情况下是否可以捕获退出代码以重新启动命令?
我已尝试过此代码,但它会直接退出255
而不重新启动:
#!/bin/bash
wait_deploy_output() {
echo "Waiting for deploy to finish..."
wait_deploy=$(aws opsworks \
--profile $AWS_PROFILE \
--region $AWS_REGION \
wait deployment-successful \
--deployment-ids $1)
wait_status=$?
[ "$wait_status" = 255 ] && wait_deploy_output $1
if [ "$wait_status" = 0 ]; then
echo "Deployed successfully!"
fi
exit $wait_status
}
wait_deploy_output $deployment_id
答案 0 :(得分:1)
嗨尝试使用以下修改后的脚本: -
#!/bin/bash
wait_status=0
wait_deploy_output() {
echo "Waiting for deploy to finish..."
wait_deploy=$(aws opsworks \
--profile $AWS_PROFILE \
--region $AWS_REGION \
wait deployment-successful \
--deployment-ids $1)
wait_status=$?
}
wait_deploy_output $deployment_id
while true
do
if [ $wait_status -eq 255 ]; then
echo "Deployment not successful"
echo "Re-deploying it again"
wait_deploy_output $deployment_id
elif [ "$wait_status" = 0 ]; then
echo "Deployed successfully!"
break
fi
done
exit $wait_status