@@ -152,7 +152,8 @@ def stackCreationComplete(stack_name, region, proxy_config):
152152 log .info ('Checking for status of the stack %s' % stack_name )
153153 cfn_client = boto3 .client ('cloudformation' , region_name = region , config = proxy_config )
154154 stacks = cfn_client .describe_stacks (StackName = stack_name )
155- return stacks ['Stacks' ][0 ]['StackStatus' ] == 'CREATE_COMPLETE'
155+ return stacks ['Stacks' ][0 ]['StackStatus' ] == 'CREATE_COMPLETE' or \
156+ stacks ['Stacks' ][0 ]['StackStatus' ] == 'UPDATE_COMPLETE'
156157
157158
158159def main ():
@@ -183,7 +184,13 @@ def main():
183184 data = {_CURRENT_IDLETIME : 0 }
184185
185186 stack_creation_complete = False
187+ termination_in_progress = False
186188 while True :
189+ # if this node is terminating sleep for a long time and wait for termination
190+ if termination_in_progress :
191+ time .sleep (300 )
192+ log .info ('%s is still terminating' % hostname )
193+ continue
187194 time .sleep (60 )
188195 if not stack_creation_complete :
189196 stack_creation_complete = stackCreationComplete (stack_name , region , proxy_config )
@@ -217,6 +224,7 @@ def main():
217224 os .remove (_IDLETIME_FILE )
218225 try :
219226 selfTerminate (asg_name , asg_conn , instance_id )
227+ termination_in_progress = True
220228 except ClientError as ex :
221229 log .error ('Failed to terminate instance: %s with exception %s' % (instance_id , ex ))
222230 lockHost (s , hostname , unlock = True )
0 commit comments