AWS Codedeploy 在安装期间失败:从 ASCII-8BIT 到 UTF-8 的未知错误"xCC"



我尝试对 Amazon Linux EC2 实例上的 CodeDeploy 代理返回的 UnknownError 进行故障排除。我将文件从 Mac 上的本地 git 存储库推送到 S3 存储桶,然后从那里部署到 EC2 实例。

我已经编辑了/etc/codedeploy-agent/conf/codedeployagent.yml 并在 EC2 实例上将 :verbose: 设置为 true。我尝试再次部署并打开 codedeploy-agent.log 在/var/log/aws/codedeploy-agent。

失败前日志中的最后一行显示代理安装了 AWS 提供的 ELB 脚本。

2015-06-19 08:09:13 DEBUG [codedeploy-agent(7637)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandBuilder: Copying /opt/codedeploy-agent/deployment-root/c6b25857-8911-4f61-8b30-b39f0c34c395/d-6UZ0VFID9/deployment-archive/scripts/stop_server.sh to /var/www/html/scripts/stop_server.sh
    2015-06-19 08:09:13 DEBUG [codedeploy-agent(7637)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandBuilder: Copying /opt/codedeploy-agent/deployment-root/c6b25857-8911-4f61-8b30-b39f0c34c395/d-6UZ0VFID9/deployment-archive/scripts/register_with_elb.sh to /var/www/html/scripts/register_with_elb.sh
    2015-06-19 08:09:13 DEBUG [codedeploy-agent(7637)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Calling PutHostCommandComplete: "Code Error" 
    2015-06-19 08:09:13 INFO  [codedeploy-agent(7637)]: [Aws::CodeDeployCommand::Client 200 0.084236 0 retries] put_host_command_complete(command_status:"Failed",diagnostics:{format:"JSON",payload:"{"error_code":5,"script_name":"","message":"\"\\xCC\" from ASCII-8BIT to UTF-8","log":""}"},host_command_identifier:"WyJjb20uYW1hem9uLmFwb2xsby5kZXBsb3ljb250cm9sLmRvbWFpbi5Ib3N0Q29tbWFuZElkZW50aWZpZXIiLHsiZGVwbG95bWVudElkIjoiQ29kZURlcGxveS9ldS13ZXN0LTEvUHJvZC9hcm46YXdzOnNkczpldS13ZXN0LTE6NzMzNTE3MzY5MDAyOmRlcGxveW1lbnQvZC02VVowVkZJRDkiLCJob3N0SWQiOiJhcm46YXdzOmVjMjpldS13ZXN0LTE6NzMzNTE3MzY5MDAyOmluc3RhbmNlL2ktZWRjYTkzNDciLCJjb21tYW5kTmFtZSI6Ikluc3RhbGwiLCJjb21tYW5kUG9zaXRpb24iOjQsImNvbW1hbmRBdHRlbXB0IjoxfV0=")

最后安装的文件不相关。因为我也试图删除我上面提到的脚本。该错误似乎是上游的,与 Ruby 相关。

2015-06-19 08:09:13 ERROR [codedeploy-agent(7637)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Error during perform: Encoding::UndefinedConversionError - "xCC" from ASCII-8BIT to UTF-8 - /opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/install_instruction.rb:165:in `encode'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/install_instruction.rb:165:in `to_json'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/install_instruction.rb:165:in `to_json'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/installer.rb:38:in `block in install'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/installer.rb:37:in `open'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/installer.rb:37:in `install'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_executor.rb:103:in `block in <class:CommandExecutor>'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_executor.rb:51:in `execute_command'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_poller.rb:123:in `process_command'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_poller.rb:56:in `perform'
/opt/codedeploy-agent/lib/instance_agent/agent/base.rb:28:in `run'
/opt/codedeploy-agent/lib/instance_agent/runner/child.rb:38:in `block in run'
/opt/codedeploy-agent/lib/instance_agent/runner/child.rb:55:in `with_error_handling'
/opt/codedeploy-agent/lib/instance_agent/runner/child.rb:37:in `run'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/child.rb:70:in `block in run_with_error_handling'
/opt/codedeploy-agent/lib/instance_agent/runner/child.rb:55:in `with_error_handling'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/child.rb:69:in `run_with_error_handling'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/child.rb:33:in `block in start'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/child.rb:22:in `loop'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/child.rb:22:in `start'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:198:in `block in spawn_child'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:196:in `fork'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:196:in `spawn_child'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:188:in `block in spawn_children'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:187:in `times'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:187:in `spawn_children'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:133:in `start'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:36:in `block in start'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:35:in `fork'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:35:in `start'
/opt/codedeploy-agent/bin/codedeploy-agent:37:in `block (2 levels) in <main>'
/opt/codedeploy-agent/vendor/gems/gli-2.5.6/lib/gli/command_support.rb:130:in `call'
/opt/codedeploy-agent/vendor/gems/gli-2.5.6/lib/gli/command_support.rb:130:in `execute'
/opt/codedeploy-agent/vendor/gems/gli-2.5.6/lib/gli/app_support.rb:262:in `block in call_command'
/opt/codedeploy-agent/vendor/gems/gli-2.5.6/lib/gli/app_support.rb:275:in `call'
/opt/codedeploy-agent/vendor/gems/gli-2.5.6/lib/gli/app_support.rb:275:in `call_command'
/opt/codedeploy-agent/vendor/gems/gli-2.5.6/lib/gli/app_support.rb:69:in `run'
/opt/codedeploy-agent/bin/codedeploy-agent:84:in `<main>'

我已经尝试过$ grep --color -in -r 'xCC' /my/folder/它返回类似的东西

Binary file /my/folder/a.png matches

但也回来了/my/folder/wp-content/plugins/wordpress-seo/admin/class-metabox.php:348:'Ì'

所以我删除了插件并尝试使用 convmv 将文件名从 ASCII 转换为 UTF-8(它没有转换任何东西)。但没有成功。

我还根据几个 StackOverflow 线程更新了几个 gem。

如何缓解此错误?我发现来自 Amazon CodeDeploy 的错误消息很糟糕,很难进行故障排除,而且我已经没有想法了。

问题似乎是在安装/启动代码部署时未设置LANG env。

我发现,如果我通过 CLI 重新启动 CodeDeploy,那么应用程序将毫无问题地部署。

您可以通过运行以下命令检查编码进程的 LANG 环境

ps auxe |grep codede

我们通过 puppet 部署 CodeDeploy,并且必须设置 (environment => 'LANG=en_US。UTF-8') 运行时运行安装脚本。

尝试更新代码部署代理。它对我有用。通过 SSH 连接到您的实例并运行以下命令: sudo /opt/codedeploy-agent/bin/install auto

必须在部署开始时定义 LANG 环境变量,否则 CodeDeploy 安装事件将失败。

您可以通过编辑 CodeDeploy 代理服务配置来确保 CodeDeploy 具有它:

sudo vim /etc/init.d/codedeploy-agent

您可以在服务首次启动时导出变量,并带有以下行:export LANG="en_US.UTF-8"

因此,起始块将如下所示:

start() {
  echo -n $"Starting $prog:"
  export LANG="en_US.UTF-8"
  cd $AGENT_ROOT
  nohup $BIN start >/dev/null </dev/null 2>&1  # Try to start the server
  exit $?
}

一些附加说明

对我来说,问题只发生在自动缩放事件期间。换句话说,我可以手动启动实例,然后部署得很好,但在启动新实例时就不对了。 这表示一种争用条件,即服务启动后环境尚未准备就绪。我尝试通过运行来更改新贵时间:

update-rc.d -f codedeploy-agent remove
update-rc.d codedeploy-agent start 99 2 3 4 5 . stop 20 0 1 6 . 

但这没有奏效。在起始块中设置变量可以保证它及时可用。

为了确保您在 CodeDeploy 启动后立即拥有所有必需的环境变量,遵循 Amazon 的建议可能是明智的:

我们建议您使代理服务保持停止状态,并使用启动脚本启动代理服务

相关内容

  • 没有找到相关文章

最新更新