22

语境

我正在使用 Elastic Beanstalk 部署一个非常简单的测试应用程序。我有几个要使用 apt 安装的软件包。我01_installations.sh在目录中包含了一个安装脚本.platform/hooks/prebuild。当我压缩我的应用程序并部署到 Elastic Beanstalk 时,日志确认预构建脚本运行,但它没有权限。

2020/08/12 21:03:46.674234 [INFO] Executing instruction: RunAppDeployPreBuildHooks
2020/08/12 21:03:46.674256 [INFO] Executing platform hooks in .platform/hooks/prebuild/
2020/08/12 21:03:46.674296 [INFO] Following platform hooks will be executed in order: [01_installations.sh]
2020/08/12 21:03:46.674302 [INFO] Running platform hook: .platform/hooks/prebuild/01_installations.sh
2020/08/12 21:03:46.674482 [ERROR] An error occurred during execution of command [app-deploy] - [RunAppDeployPreBuildHooks]. Stop running the command. Error: Command .platform/hooks/prebuild/01_installations.sh failed with error fork/exec .platform/hooks/prebuild/01_installations.sh: permission denied  

问题

我的理解是权限被拒绝,因为我没有添加chmod +x使 .sh 文件可执行。正如有关平台挂钩的 AWS 文档所述:“使用 chmod +x 设置挂钩文件的执行权限。” (https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html)。我的问题是:我该怎么做?

我只是将 .sh 文件放在一个目录中。我不会从其他任何地方调用它。我缺少一个简单的步骤吗?AWS 文档让它看起来应该很简单。

以前的尝试

我尝试过的事情:

  1. 添加 .ebextensions
    • 尝试:使用以下命令在目录中创建一个.config文件,该文件应以 chmod +x 权限执行 .sh 文件。.ebextensions
    • 结果:出现同样的错误。Elastic Beanstalk 日志根本不表示.config已处理。
container_commands:
    01_chmod1:
        command: "chmod +x .platform/hooks/prebuild/01_installations.sh"
  1. 更改 .sh 文件的名称
    • 尝试:按照 AWS 用户的建议将 .sh 文件命名为“chmod +x 01_installations.sh”(下面的论坛链接)。删除 .ebextensions
    • 结果:出现同样的错误。
[RunAppDeployPreBuildHooks]. Stop running the command. Error: Command .platform/hooks/prebuild/chmod +x 01_installations.sh failed with error fork/exec .platform/hooks/prebuild/chmod +x 01_installations.sh: permission denied 

我在这里回顾了这些想法,但它们实际上都没有包含足够完整的示例来遵循:

4

3 回答 3

16

确保使您的文件在 git 中可执行

chmod +x path/to/file
git update-index --chmod=+x path/to/file

参考 如何在 GIT 中向文件添加 chmod 权限?

于 2020-09-01T18:39:38.557 回答
12

通常,在压缩部署包之前,您可以在本地工作站上设置权限。

但是,如果您想在 EB 实例上执行此操作,则不能container_commands用于此操作。原因是之后container_commands执行。相反,您应该尝试使用: prebuildcommands

预构建文件在运行任何配置文件的命令部分中的命令之后和运行构建文件命令之前运行。

于 2020-08-13T21:38:20.813 回答
0

在更新权限提交更改后,这对我有用。

此外,.config文件中的命令将不起作用,因为这些命令将在部署前运行,因此无法找到.sh文件的路径。

于 2021-09-01T17:04:52.870 回答