AWS codedeploy throwing throw "[stderr] Could not open input file" when trying to call php file from sh file at afterInstall

I have the following definition in the appspec file -

hooks: AfterInstall: - location: afterInstall.sh 

The following is the contents of afterInstall.sh (I'm trying to call a php file from a sh file) -

 php afterInstall.php 

Both afterInstall.sh and afterInstall.php files are on the same level (the most external level) in the zip archive, which I upload to S3 -

 appspec.yml afterInstall.sh afterInstall.php 

I get the following error:

 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 

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

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

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

I'm a little confused about what the permissions section does. From http://docs.aws.amazon.com/codedeploy/latest/userguide/app-spec-ref-permissions.html ,

The Permissions section indicates how special permissions, if any, should be applied to files and directories / folders in files after copying to an instance.

I also tried to specify the owner / group as root / root and runas: root against hook after installation, but still get the same error.

Update

I also tried to specify the afterInstall.php file in the file section and make sure that its permissions and rights are correct -

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

In / var / cake_1.2.0.6311-beta -

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

I have no other idea what else needs to be done to fix this.

Note. I can successfully deploy if I do not call the php file from the afterInstall.sh file

0
source share
2 answers

The main reason for the error is that the link to the php file is incorrect. Your script assumes that the current working directory is the destination folder or the deployment archive folder.

This is a reasonable assumption, but none of them 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 error "Could not open input file."

Since you are in the afterInstall cache, all of your files already exist at 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 

This will allow php to find the correct file and the deployment will start successfully.

Update:

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

This can be done in one of the following ways:

  • Use user-data script to load the script when starting the instance of the instance or
  • Bake the script into an AMI image and launch from that image.

In any case, the hook beforeInstall can call the script on its fixed path, for example php /tools/beforeInstall.php .

I prefer option 1 in these cases. We support an S3 bucket with asset types that are then supported on S3 and loaded into each instance at startup. Any updates are carried over to S3 and called for each launch of a new instance.

+1
source
  • An object record can be a directory or a file, the current value is "." Corresponds to the directory of the CodeDeploy deployment archive, and not to the destination into which the scripts were copied. Therefore, perhaps you can try to use the file destination directory as an object.

  • And since the directory for the CodeDeploy deployment archive contains all the files from the client bundle. I'm not quite sure about your file directory, but if all the objects in the deployment archive directory are directories, perhaps the type that can be changed can be changed to a directory.

The file section is as follows: this section contains the names of the files that should be copied to the instance during the deployment setup event.

files: - source: source-file-location destination: destination-file-location

While the hook section looks like the following structure, the Hooks section of the AppSpec file contains mappings linking the deployment lifecycle event hooks to one or more scenarios. If the event hook is missing, then the operation is not performed for this event. This section is required only if you will run scripts as part of the deployment.

hooks: deployment-lifecycle-event-name - location: script-location timeout: timeout-in-seconds runas: user-name

0
source

Source: https://habr.com/ru/post/1233646/


All Articles