外壳脚本的 AWS 代码部署部署失败



我尝试使用Cloud Formation Stack创建CodeDeploy部署组。每次我运行堆栈时,都会遇到脚本错误,例如解释器错误、找不到 rm/ll 命令、/r/n 错误。我尝试使用 dos2unix 更改 shell 脚本文件并压缩这些文件并上传到 CodeDeploy,但没有成功。

以下是我在日志中收到的错误语句:

2018-09-01 10:41:45 INFO  [codedeploy-agent(2681)]: [Aws::CodeDeployCommand::Client 200 0.037239 0 retries] put_host_command_complete(command_status:"Failed",diagnostics:{format:"JSON",payload:"{"error_code":4,"script_name":"BeforeInstall.sh","message":"Script at specified location: BeforeInstall.sh run as user root failed with exit code 127","log":"LifecycleEvent - BeforeInstall\nScript - BeforeInstall.sh\n[stderr]/usr/bin/env: bash\r: No such file or directory\n"}"},host_command_identifier:"WyJjb20uYW1hem9uLmFwb2xsby5kZXBsb3ljb250cm9sLmRvbWFpbi5Ib3N0Q29tbWFuZElkZW50aWZpZXIiLHsiZGVwbG95bWVudElkIjoiQ29kZURlcGxveS91cy1lYXN0LTEvUHJvZC9hcm46YXdzOnNkczp1cy1lYXN0LTE6OTkzNzM1NTM2Nzc4OmRlcGxveW1lbnQvZC05V0kzWk5DNlYiLCJob3N0SWQiOiJhcm46YXdzOmVjMjp1cy1lYXN0LTE6OTkzNzM1NTM2Nzc4Omluc3RhbmNlL2ktMDk1NGJlNjk4OTMzMzY5MjgiLCJjb21tYW5kTmFtZSI6IkJlZm9yZUluc3RhbGwiLCJjb21tYW5kUG9zaXRpb24iOjMsImNvbW1hbmRBdHRlbXB0IjoxfV0=")
2018-09-01 10:41:45 ERROR [codedeploy-agent(2681)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Error during perform: InstanceAgent::Plugins::CodeDeployPlugin::ScriptError - Script at specified location: BeforeInstall.sh run as user root failed with exit code 127 - /opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/hook_executor.rb:173:in `execute_script'
......
......
2018-09-01 10:41:45 INFO  [codedeploy-agent(2681)]: [Aws::CodeDeployCommand::Client 200 0.018288 0 retries] put_host_command_complete(command_status:"Failed",diagnostics:{format:"JSON",payload:"{"error_code":5,"script_name":"","message":"Script at specified location: BeforeInstall.sh run as user root failed with exit code 127","log":""}"},host_command_identifier:"WyJjb20uYW1hem9uLmFwb2xsby5kZXBsb3ljb250cm9sLmRvbWFpbi5Ib3N0Q29tbWFuZElkZW50aWZpZXIiLHsiZGVwbG95bWVudElkIjoiQ29kZURlcGxveS91cy1lYXN0LTEvUHJvZC9hcm46YXdzOnNkczp1cy1lYXN0LTE6OTkzNzM1NTM2Nzc4OmRlcGxveW1lbnQvZC05V0kzWk5DNlYiLCJob3N0SWQiOiJhcm46YXdzOmVjMjp1cy1lYXN0LTE6OTkzNzM1NTM2Nzc4Omluc3RhbmNlL2ktMDk1NGJlNjk4OTMzMzY5MjgiLCJjb21tYW5kTmFtZSI6IkJlZm9yZUluc3RhbGwiLCJjb21tYW5kUG9zaXRpb24iOjMsImNvbW1hbmRBdHRlbXB0IjoxfV0=")

失败的可能原因是什么?

日志表明您的脚本存在一些问题,特别是BeforeInstall.sh.该脚本中的某些内容失败,退出代码为 127。我建议将日志添加到该脚本以查看它实际失败的位置。确定失败的命令后,可以看到退出代码 127 对该特定命令的含义。

如果需要调试该特定脚本的帮助,则应打开另一个问题并提供脚本,包括运行时的日志。

CodeDeploy 生命周期挂钩的说明

在您的情况下,您的BeforeInstall脚本失败,这将是与您的应用程序一起部署的脚本。但是,如果失败的是ApplicationStop脚本,请务必了解ApplicationStop使用上次成功部署中的脚本,因此,如果上次成功部署具有错误脚本,则可能会导致将来的部署失败,直到执行这些步骤。

相关内容

  • 没有找到相关文章

最新更新