Skip to content

Commit 0d9fc94

Browse files
Re-integrated fixes from dependent project
One of our customers gave us permission to re-integrate these fixes. Ask @obscurerichard for details.
1 parent 5ae86c6 commit 0d9fc94

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

bin/rotate-asg.sh

+21
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ asg_DesiredCapacity="$(aws autoscaling describe-auto-scaling-groups \
8585
--output text)"
8686

8787
asg_MaxSize=$(aws autoscaling describe-auto-scaling-groups \
88+
--auto-scaling-group-name "$asg_name" \
8889
--query 'AutoScalingGroups[].MaxSize' \
8990
--output text)
9091

@@ -105,13 +106,17 @@ aws autoscaling update-auto-scaling-group \
105106
--output table
106107

107108
# Wait until new instances spin up
109+
echo -n "Waiting until new instances are in service"
108110
current_asg_instances="$(get_asg_instances "$asg_name")"
109111
while num_in_service_less_than "$current_asg_instances" "$asg_NewCapacity"; do
110112
sleep 5
113+
echo -n "."
111114
current_asg_instances="$(get_asg_instances "$asg_name")"
112115
done
116+
echo ""
113117

114118
# Terminate old instances explicitly
119+
echo "Terminating old instances $original_asg_instances"
115120
for instance in $original_asg_instances; do
116121
aws autoscaling terminate-instance-in-auto-scaling-group \
117122
--instance-id "$instance" \
@@ -124,4 +129,20 @@ aws autoscaling update-auto-scaling-group \
124129
--max-size "$asg_MaxSize" \
125130
--output table
126131

132+
# Wait for old instances to complete termination
133+
for instance in $original_asg_instances; do
134+
echo ""
135+
echo -n "Waiting for $instance to terminate"
136+
while aws ec2 describe-instances \
137+
--instance-id "$instance" \
138+
--query 'Reservations[*].Instances[*].State.Name' \
139+
--output text \
140+
| grep -v '^terminated$' >/dev/null
141+
do
142+
echo -n "."
143+
sleep 5
144+
done
145+
done
146+
echo ""
127147

148+
echo "Rotate complete. New ASG instances: $(get_asg_instances "$asg_name")"

0 commit comments

Comments
 (0)