AWS Codedeploy错误:scripts / applicationstart.sh不可执行。试图让它可执行

时间:2017-06-02 02:07:41

标签: node.js bash amazon-web-services aws-code-deploy

我在EC2实例上运行Ubuntu并尝试设置代码部署以运行脚本以在appspec.yml中配置部署。但是,这些钩子脚本似乎没有运行。当我检查代码部署错误日志时,我看到错误消息InstanceAgent::Plugins::CodeDeployPlugin::HookExecutor: Script at specified location: scripts/applicationstart.sh is not executable. Trying to make it executable.

这非常令人困惑,因为我的脚本非常简单,我不确定为什么不接受它们。以下是在appspec.yml文件中调用它们的地方:

version: 0.0
os: linux
files:
  - source: /
    destination: /home/ubuntu/teller-install
hooks:
  BeforeInstall:
    - location: scripts/beforeinstall.sh
      timeout: 300
      runas: root
  ApplicationStart:
    - location: scripts/applicationstart.sh
      timeout: 300
      runas: root

以下是我调用的两个脚本:

#!/bin/bash

cd /home/ubuntu/teller-install/Server && npm install
exit 0

第二个:

    #!/bin/bash

pm2 start /home/ubuntu/teller-install/Server/app.js
exit 0

部署成功但脚本未运行。

以下是我在codedeploy-agent日志文件中收到的错误消息:

    2017-06-01 23:59:01 WARN  [codedeploy-agent(3504)]: InstanceAgent::Plugins::CodeDeployPlugin::HookExecutor: Script at specified location: scripts/applicationstart.sh is not executable.  Trying to make it executable.
2017-06-01 23:59:01 INFO  [codedeploy-agent(3504)]: Version file found in /opt/codedeploy-agent/.version.
2017-06-01 23:59:01 INFO  [codedeploy-agent(3504)]: [Aws::CodeDeployCommand::Client 200 0.028596 0 retries] put_host_command_complete(command_status:"Succeeded",diagnostics:{format:"JSON",payload:"{\"error_code\":0,\"script_name\":\"\",\"message\":\"Succeeded\",\"log\":\"\"}"},host_command_identifier:"WyJjb20uYW1hem9uLmFwb2xsby5kZXBsb3ljb250cm9sLmRvbWFpbi5Ib3N0Q29tbWFuZElkZW50aWZpZXIiLHsiZGVwbG95bWVudElkIjoiQ29kZURlcGxveS91cy1lYXN0LTEvUHJvZC9hcm46YXdzOnNkczp1cy1lYXN0LTE6MDEwNzAyMDY3ODAwOmRlcGxveW1lbnQvZC1LWFU2WjQ0UU0iLCJob3N0SWQiOiJhcm46YXdzOmVjMjp1cy1lYXN0LTE6MDEwNzAyMDY3ODAwOmluc3RhbmNlL2ktMGNkMzQ3OThlNDdiYzE3MjkiLCJjb21tYW5kTmFtZSI6IkFwcGxpY2F0aW9uU3RhcnQiLCJjb21tYW5kUG9zaXRpb24iOjYsImNvbW1hbmRBdHRlbXB0IjoxfV0=")  

以下是我正在谈论的文件的源代码。

https://github.com/SamKirkiles/Teller

2 个答案:

答案 0 :(得分:1)

好的,经过很多挫折我解决了这个问题。首先,我必须使用chmod 777 scriptname.sh更改我的脚本的权限,但是你想要给予他们比实际更严格的权限。这摆脱了那个恼人的错误信息。

然后脚本不工作的原因是因为我有我的脚本,我在安装挂钩之前安装了依赖项,并且在任何文件出现之前调用它。我必须将依赖安装移到安装后,一切都运行良好。希望能帮助任何有类似问题的人。

答案 1 :(得分:0)

我认为这里有些误解。这是可以理解的,因为CodeDeploy在解释它方面做得很差。

警告... is not executable. Trying to make it executable.有点像鲱鱼。请参阅OP的代码段的下一行,其中指出确实确实已成功将脚本设置为可执行文件:put_host_command_complete(command_status:"Succeeded" ...

因此,您完全不必为hooks脚本设置权限-CodeDeploy会为您处理这些权限。

请注意,还有其他烦人的特性。 CodeDeploy不会从您选择的代码位置(例如hooks)执行/srv/my-cool-app/scripts/beforeinstall.sh脚本。实际上,它会复制整个部署,并将其存储在/opt/codedeploy-agent/deployment-root/[some-guid]/[newest-folder]/deployment-archive/中。这是运行hooks脚本的地方。您可以通过转到该文件夹​​并在该文件夹中检查脚本的权限来查看此证明-由CodeDeploy代理运行的脚本的权限为777。

此外,尽管您可以在appspec.yml文件中放置一个permissions部分,但它需要绝对路径,这再次仅允许您编辑部署位置,而不是脚本所在的/ opt位置实际运行。