Search code examples
node.jsbashamazon-web-servicesaws-code-deploy

AWS Codedeploy error: scripts/applicationstart.sh is not executable. Trying to make it executable


I am running Ubuntu on an EC2 instance and trying to set up code deploy to run scripts to provision the deployment in appspec.yml. However, these hook scripts do not seem to be running. When I check the code deploy error logs, I see the error message InstanceAgent::Plugins::CodeDeployPlugin::HookExecutor: Script at specified location: scripts/applicationstart.sh is not executable. Trying to make it executable.

This is very confusing because my scripts are very simple and I am not sure why they would not be accepted. Here is where they are called in the appspec.yml file:

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

Here are the two scripts I am calling form this:

#!/bin/bash

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

And the second:

    #!/bin/bash

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

The deployment succeeds but the scripts are not run.

Here is the error message i get in the codedeploy-agent log file:

    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=")  

Here is the source code with the files I am talking aboout.

https://github.com/SamKirkiles/Teller


Solution

  • Ok so after a lot of frustration I solved the problem. First of all, I had to change the permissions on my scripts with chmod 777 scriptname.sh but you're going to want to give them tighter permissions than that in reality. This got rid of that annoying error message.

    Then the reason the scripts were not working was becasue I had my script where I installed dependencies in before install hook and that is calling it before any of the files are present. I had to move the dependency installation into after install and everything is working perfectly. Hope that helps anyone with a similar problem.