抛出"[stderr]无法打开输入文件"的AWS Codedeploy部署.在afterInstall步骤中尝试从sh文件调用php文件时 [英] AWS codedeploy deployment throwing "[stderr] Could not open input file" while trying to invoke a php file from the sh file at afterInstall step

查看:101
本文介绍了抛出"[stderr]无法打开输入文件"的AWS Codedeploy部署.在afterInstall步骤中尝试从sh文件调用php文件时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在appspec文件中定义了以下内容-

I have the following defined in the appspec file -

hooks:
  AfterInstall:
    - location: afterInstall.sh 

以下是afterInstall.sh的内容(我正在尝试从sh文件调用php文件)-

Following is the content of afterInstall.sh (I am trying to invoke a php file from the sh file) -

php afterInstall.php

afterInstall.sh和afterInstall.php文件在我要上传到S3的zip归档文件中处于同一级别(最外层)-

Both the files afterInstall.sh and afterInstall.php are at the same level (outermost level) in the zip archive that I am uploading to S3 -

appspec.yml
afterInstall.sh
afterInstall.php

我收到以下错误-

Error Code         ScriptFailed
Script Name        afterInstall.sh
Message            Script at specified location: afterInstall.sh failed with exit code 1

Log Tail          LifecycleEvent - AfterInstall
                  Script - afterInstall.sh
                  [stderr]Could not open input file: afterInstall.php

我还尝试通过将以下内容添加到apppsec文件的权限部分-

I also tried by adding the following to the permissions section of the apppsec file -

permissions:
  - object: .
    pattern: "**"
    owner: sandeepan
    group: sandeepan
    mode: 777
    type:
      - file

注意-我具有使用sandeepan用户的部署实例的登录凭据.

Note - I have the login credentials of the deployment instances using the sandeepan user.

我对权限部分的功能有些困惑.来自 http://docs.aws.amazon. com/codedeploy/latest/userguide/app-spec-ref-permissions.html

I am a bit confused with what exactly the permissions section does. From http://docs.aws.amazon.com/codedeploy/latest/userguide/app-spec-ref-permissions.html,

权限部分指定特殊权限(如果有)的方式, 应该应用于文件以及文件中的目录/文件夹 将它们复制到实例之后.

The permissions section specifies how special permissions, if any, should be applied to the files and directories/folders in the files section after they are copied to the instance.

我还尝试通过将所有者/组指定为root/root和runas:root来代替afterInstall挂钩,但是仍然出现相同的错误.

I also tried by specifying owner/group as root/root and runas: root against the afterInstall hook, but still getting the same error.

更新

我还尝试通过在文件部分中指定afterInstall.php文件,并确保其权限和所有权正确-

I also tried by specifying the afterInstall.php file in the files section, and ensuring its permission and ownerships are correct -

  - source: afterInstall.php
    destination: /var/cake_1.2.0.6311-beta

在/var/cake_1.2.0.6311-beta-

At /var/cake_1.2.0.6311-beta -

-rwxrwxr-x  1 sandeepan sandeepan   26 Aug  1 08:55 afterInstall.php

我没有其他线索可以解决此问题.

I have no other clue what else should be done to fix this.

注意-如果我不从afterInstall.sh

Note - I am able to deploy successfully if I do not call a php file from the afterInstall.sh

推荐答案

该错误的根本原因是php文件引用不正确.您的脚本假定当前工作目录是目标文件夹或部署存档文件夹.

The root cause of the error is that the php file reference is incorrect. Your script assumes that the current working directory is the the destination folder, or the deployment archive folder.

这是一个合理的假设,但是这两个都不正确.在我的Ubuntu服务器上,CodeDeploy Shell调用的当前工作目录实际上是/opt/codedeploy-agent.这说明了为什么出现无法打开输入文件"错误的原因.

This is a reasonable assumption, however neither of these is correct. On my Ubuntu server, the current working directory of the CodeDeploy shell invocation is actually /opt/codedeploy-agent. This explains why you get the "Could not open input file" error.

由于您处于afterInstall生命周期挂钩中,因此所有文件都已存在于最终目标中.要解决此问题,请在afterInstall.sh中使用destination:指令中指定的路径:

Since you are in the afterInstall lifecycle hook, all your files already exist in the final destination. To solve the problem, use the path specified in the destination: directive in your afterInstall.sh:

#!/bin/bash
php /var/cake_1.2.0.6311-beta/afterInstall.php

这将使php找到正确的文件,并且您的部署将成功运行.

This will allow php to locate the correct file, and you deployment will run successfully.

更新:

如果要在beforeInstall挂钩中运行文件,则该文件必须已存在于系统上,并由固定路径(例如/tools)引用.

If you want to run a file in the beforeInstall hook, the file must already exist on the system, and be referenced by a fixed path such as /tools.

这可以通过以下方法之一完成:

This can be accomplished by one of the following:

  1. 使用user-data脚本在实例启动时下载该脚本,或者
  2. 将脚本烘焙"到AMI映像本身,然后从该映像启动.
  1. Use a user-data script to download the script at instance launch time, or
  2. 'Baking' the script into the AMI image itself, and launching from that image.

无论哪种情况,beforeInstall挂钩都可以从其固定路径(例如php /tools/beforeInstall.php)调用脚本.

In either case, the beforeInstall hook can then call the script from its fixed path, eg php /tools/beforeInstall.php.

在这些情况下,我更喜欢选项1.我们使用这些资产类型维护一个S3存储桶,然后将其保留在S3上,并在启动时下载到每个实例.任何更新都会推送到S3,并在每次新实例启动时调用.

I prefer option 1 in these cases. We maintain an S3 bucket with these type of assets, which are then maintained on S3, and downloaded to each instance at launch time. Any updates are pushed to S3, and are called for each new instance launch.

这篇关于抛出"[stderr]无法打开输入文件"的AWS Codedeploy部署.在afterInstall步骤中尝试从sh文件调用php文件时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆