AWS Codedeploy error: scripts/applicationstart.sh is not executable. Trying to make it executable
AWS Codedeploy error: scripts/applicationstart.sh is not executable. Trying to make it executable
我在 EC2 实例上 运行 宁 Ubuntu 并尝试设置代码部署到 运行 脚本以在 appspec.yml 中配置部署。然而,这些钩子脚本似乎并不运行ning。当我检查代码部署错误日志时,我看到错误消息 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=")
这是我正在谈论的文件的源代码。
好吧,在经历了很多挫折之后,我解决了这个问题。首先,我必须使用 chmod 777 scriptname.sh
更改我的脚本的权限,但你会想要给它们比实际更严格的权限。这摆脱了烦人的错误消息。
然后脚本不工作的原因是因为我有我的脚本,我在安装挂钩之前安装了依赖项,并且在任何文件存在之前调用它。我必须在安装后将依赖项安装移动到其中,并且一切正常。希望对遇到类似问题的人有所帮助。
我认为这里有些误解。可以理解,因为 CodeDeploy 解释得不好。
警告 ... is not executable. Trying to make it executable.
有点转移注意力。请参阅 OP 片段中的下一行,它确实成功地将脚本设置为可执行:put_host_command_complete(command_status:"Succeeded" ...
因此您根本不必在 hooks
脚本上设置权限 - CodeDeploy 会为您处理。
请注意,还有一个令人讨厌的特性。 CodeDeploy 不会从您选择的代码位置(例如,/srv/my-cool-app/scripts/beforeinstall.sh
)执行您的 hooks
脚本。它实际上制作了整个部署的副本并将其存储在 /opt/codedeploy-agent/deployment-root/[some-guid]/[newest-folder]/deployment-archive/
中。这是 运行 的 hooks
脚本来源。您可以通过转到该文件夹并检查您的脚本的权限来查看这一点的证据 - CodeDeploy 代理 运行 的权限将为 777.
此外,虽然您可以在 appspec.yml 文件中放置一个 permissions
部分,但它需要绝对路径,这同样只允许您编辑部署位置,而不是 /opt 位置脚本实际上来自 运行。
我在 EC2 实例上 运行 宁 Ubuntu 并尝试设置代码部署到 运行 脚本以在 appspec.yml 中配置部署。然而,这些钩子脚本似乎并不运行ning。当我检查代码部署错误日志时,我看到错误消息 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=")
这是我正在谈论的文件的源代码。
好吧,在经历了很多挫折之后,我解决了这个问题。首先,我必须使用 chmod 777 scriptname.sh
更改我的脚本的权限,但你会想要给它们比实际更严格的权限。这摆脱了烦人的错误消息。
然后脚本不工作的原因是因为我有我的脚本,我在安装挂钩之前安装了依赖项,并且在任何文件存在之前调用它。我必须在安装后将依赖项安装移动到其中,并且一切正常。希望对遇到类似问题的人有所帮助。
我认为这里有些误解。可以理解,因为 CodeDeploy 解释得不好。
警告 ... is not executable. Trying to make it executable.
有点转移注意力。请参阅 OP 片段中的下一行,它确实成功地将脚本设置为可执行:put_host_command_complete(command_status:"Succeeded" ...
因此您根本不必在 hooks
脚本上设置权限 - CodeDeploy 会为您处理。
请注意,还有一个令人讨厌的特性。 CodeDeploy 不会从您选择的代码位置(例如,/srv/my-cool-app/scripts/beforeinstall.sh
)执行您的 hooks
脚本。它实际上制作了整个部署的副本并将其存储在 /opt/codedeploy-agent/deployment-root/[some-guid]/[newest-folder]/deployment-archive/
中。这是 运行 的 hooks
脚本来源。您可以通过转到该文件夹并检查您的脚本的权限来查看这一点的证据 - CodeDeploy 代理 运行 的权限将为 777.
此外,虽然您可以在 appspec.yml 文件中放置一个 permissions
部分,但它需要绝对路径,这同样只允许您编辑部署位置,而不是 /opt 位置脚本实际上来自 运行。