#NEWLINE# def watchTermination( self , container , component ) : #NEWLINE# #INDENT# report ( 'Monitor check started' , level = ReportLevels . BACKGROUND ) #NEWLINE# client = getDockerClient ( ) #NEWLINE# signals = [ ] #NEWLINE# for signal in component . config . termination_signals : #NEWLINE# #INDENT# signals . append ( ( signal , buildTerminationSignal ( signal ) ) ) #NEWLINE# #UNINDENT# report ( ( 'Sending %s termination signals' % len ( signals ) ) , component = component ) #NEWLINE# for ( config , signal ) in signals : #NEWLINE# #INDENT# report ( ( 'Sending termination signal: ' + config . getTitle ( ) ) , component = component ) #NEWLINE# result = signal . run ( container , report ) #NEWLINE# if ( not result ) : #NEWLINE# #INDENT# report ( 'Termination signal failed' , component = component ) #NEWLINE# #UNINDENT# #UNINDENT# checks = [ ] #NEWLINE# for check in client . config . termination_checks : #NEWLINE# #INDENT# checks . append ( ( check , buildHealthCheck ( check ) ) ) #NEWLINE# #UNINDENT# report ( ( 'Waiting for %s termination checks' % len ( checks ) ) , component = component ) #NEWLINE# for ( config , check ) in checks : #NEWLINE# #INDENT# check_passed = False #NEWLINE# while ( not check_passed ) : #NEWLINE# #INDENT# report ( ( 'Running termination check: ' + config . getTitle ( ) ) , component = component ) #NEWLINE# result = check . run ( container , report ) #NEWLINE# if ( not result ) : #NEWLINE# #INDENT# report ( 'Termination check failed' , component = component ) #NEWLINE# report ( ( ( 'Sleeping ' + str ( config . timeout ) ) + ' second(s)...' ) , component = component ) #NEWLINE# time . sleep ( config . timeout ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# check_passed = True #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# report ( 'Monitor check finished' , level = ReportLevels . BACKGROUND ) #NEWLINE# setContainerStatus ( container , 'shutting-down' ) #NEWLINE# report ( ( 'Shutting down container: ' + container [ 'Id' ] [ 0 : 12 ] ) , level = ReportLevels . BACKGROUND ) #NEWLINE# client . stop ( container ) #NEWLINE# removeContainerMetadata ( container )