如何等待 10 多分钟在 AWS Opsworks 上部署成功?

How to wait for more than 10 minutes a successful deployment on AWS Opsworks?

我正在使用 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 )

  wait_status=$?

  [ "$wait_status" = 255 ] && wait_deploy_output 

  if [ "$wait_status" = 0 ]; then
    echo "Deployed successfully!"
  fi

  exit $wait_status
}

wait_deploy_output $deployment_id

您好尝试使用以下修改后的脚本:-

#!/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 )

  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