Issue
I am deploying an application on AWS using AWS Opsworks
. I have automated the deployment in a script, and I would like to make my task last as long as the deployment has not been finished on Opsworks
.
I am using the command deployment-successful
to do it, but it exits 255
after 10 minutes if the deployment is not finished yet. And sometimes our Opsworks
deployments last longer than than 10 minutes. Is it possible to catch the exit code to relaunch the command in such case?
I have tried this code but it exits directly 255
without relaunching:
#!/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
Solution
Hi Try with the below modified script:-
#!/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
Answered By - Abhijit Pritam Dutta Answer Checked By - Clifford M. (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.