Ошибка CodeDeploy: не удалось удалить экземпляр из Loadbalancer - PullRequest
0 голосов
/ 21 января 2020

Я получаю приведенную ниже ошибку развертывания кода в AWS Консоль

LifecycleEvent - ApplicationStop
Script - scripts/deregister_from_elb.sh
[stderr]Running AWS CLI with region: us-east-1
[stderr]Started deregister_from_elb.sh at 2020-01-21 10:53:43
[stderr]Checking that user set at least one load balancer
[stderr]Checking validity of load balancer named 'lb'
[stderr]Checking health of 'i-xxxxxxxxxxxxxxxx' as known by ELB 'lb'
[stderr]Checking status of instance 'i-xxxxxxxxxxxxxxxx' in load balancer 'lb'
[stderr]Deregistering i-xxxxxxxxxxxxxxxx from lb
[stderr]Waiting for instance to de-register from its load balancers
[stderr]Checking 2 times, every 70 seconds, for instance i-xxxxxxxxxxxxxxxx to be in state OutOfService
[stderr]Checking status of instance 'i-xxxxxxxxxxxxxxxx' in load balancer 'lb'
[stderr]Instance is currently in state: InService
[stderr]Checking status of instance 'i-xxxxxxxxxxxxxxxx' in load balancer 'lb'
[stderr]Instance is currently in state: InService
[stderr]Instance failed to reach state, OutOfService within 140 seconds
[stderr][FATAL] Failed waiting for i-xxxxxxxxxxxxxxxx to leave lb

При проверке файла журнала агента развертывания кода в EC2 Экземпляр показывает:

ERROR [codedeploy-agent(14347)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Error during perform: InstanceAgent::Plugins::CodeDeployPlugin::ScriptError - Script at specified location: scripts/deregister_from_elb.sh failed with exit code 1 -
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/hook_executor.rb:183:in `execute_script'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/hook_executor.rb:129:in `block (2 levels) in execute'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/hook_executor.rb:117:in `each'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/hook_executor.rb:117:in `block in execute'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/hook_executor.rb:208:in `create_script_log_file_if_needed'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/hook_executor.rb:115:in `execute'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_executor.rb:158:in `block (3 levels) in map'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_executor.rb:146:in `each'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_executor.rb:146:in `block (2 levels) in map'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_executor.rb:68:in `execute_command'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_poller.rb:114:in `process_command'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_poller.rb:96:in `acknowledge_and_process_command'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_poller.rb:75:in `block in perform'
/opt/codedeploy-agent/vendor/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:348:in `call'
/opt/codedeploy-agent/vendor/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:348:in `run_task'
/opt/codedeploy-agent/vendor/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:337:in `block (3 levels) in create_worker'
/opt/codedeploy-agent/vendor/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:320:in `loop'
/opt/codedeploy-agent/vendor/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:320:in `block (2 levels) in create_worker'
/opt/codedeploy-agent/vendor/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:319:in `catch'
/opt/codedeploy-agent/vendor/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:319:in `block in create_worker'
/opt/codedeploy-agent/vendor/gems/logging-1.8.2/lib/logging/diagnostic_context.rb:323:in `call'
/opt/codedeploy-agent/vendor/gems/logging-1.8.2/lib/logging/diagnostic_context.rb:323:in `block in create_with_logging_context'
2020-01-21 10:54:56 WARN  [codedeploy-agent(14347)]:
InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Calling PutHostCommandComplete: "Code Error" 
2020-01-21 10:54:56 WARN  [codedeploy-agent(14347)]: 
InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Calling PutHostCommandComplete: "Code Error" 
2020-01-21 10:54:56 INFO  [codedeploy-agent(14347)]: Version file found in /opt/codedeploy-agent/.version with agent version OFFICIAL_1.0-1.1597_deb.
2020-01-21 10:54:56 INFO  [codedeploy-agent(14347)]: Version file found in /opt/codedeploy-agent/.version with agent version OFFICIAL_1.0-1.1597_deb.
2020-01-21 10:54:56 INFO  [codedeploy-agent(14347)]: [Aws::CodeDeployCommand::Client 200 0.186875 0 retries] put_host_command_complete(command_status:"Failed",diagnostics:{format:"JSON",payload:"{\"error_code\":5,\"script_name\":\"\",\"message\":\"Script at specified location: scripts/deregister_from_elb.sh failed with exit code 1\",\"log\":\"\"}"},host_command_identifier:"1YmxpYzAwMS9hcm46YXdzOnNkczp1cy1lYXN0LTE6MTMxMjE0OTI1MjQ1OmRlcGxveW1lbnQvZC1LVjgyTVRPNTIiLCJob3N0SWQiOiJhcm46YXdzOmVjMjp1cy1lYXN0LTE6MTMxMjE0OT1MjQ1Omluc3RhbmNlL2ktMDFhMGFiMjlhMWM2NjEwNjJ8MXwwIiwiY29tbWFuZE5hbWUiOiJBcHBsaWNhdGlvblN0b3AiLRleCI6MX0=") 

Я решил проблему временно удалив все содержимое в папке / opt / codedeploy-agent / deploy- root и перезапустив службу агента развертывания кода. Но проблема повторяется через некоторое время. Кто-нибудь знал, почему это происходит?

Ответы [ 2 ]

0 голосов
/ 22 января 2020

Я предполагаю, что вы используете этот скрипт:

Лучше всего будет посмотреть события CloudTrail во время выполнение этого сценария, чтобы увидеть любые сбойные вызовы ELB (в частности, вызовы 'DeregisterInstancesFromLoadBalancer' и 'DescribeInstanceHealth'). AWS Консоль CodeDeploy дает точное время запуска сценария жизненного цикла. Похоже, что ELB не может полностью отменить регистрацию экземпляра EC2.

0 голосов
/ 21 января 2020

Сценарий scripts/deregister_from_elb.sh не работает из-за ошибки доступа. Вам необходимо проверить выполнение кода, в частности файловые операции. Добавьте флаги -xev в строку !#/usr/bin/bash (чтобы она читала !#/usr/bin/bash -xev, и повторите попытку. Это приведет к подробному ведению журнала ошибок скрипта и должно показать вам, где находится ошибка.

...