3

I am using CodeDeploy to deploy my applications to EC2 instances created by an Auto Scaling Group.

The applications deploy fine and are moved to their correct file mapped locations, however my AfterInstallation script is never executed. I can see in the logs that it tries to make the script executable and passes that stage, but it never gets executed.

Here is my appspec.yml

version: 0.0 os: linux files: - source: / destination: /opt/lobby hooks: AfterInstall: - location: bootstrap.sh timeout: 30 runas: root 

Here is the script

#!/bin/bash nohup nodejs lobby.js & echo "finished" 

I do not see the echo printed nor do I see any processes running related to lobby.js. I can verify that this script works by typing ./bootstrap.sh after the deployment and this works fine. This hook should do this for me though.

This needs to be a background task as I will be running multiple applications in this script but only one is displayed now just to get it working.


Edit:

I have referred to http://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-hooks.html#appspec-hooks-server and tried replacing AfterInstall with ValidateService and AfterAllowTraffic (but I'm not using a LoadBalancer)

Question

Why is my AfterInstallation script not getting called, or so it seems?

2
  • Are you certain that the file is in the same folder as appspec.yml? If so, try Location: ./bootstrap.sh Commented Dec 21, 2017 at 20:12
  • Yeah, I found the issue after a bit of digging. There were some errors being thrown in the execution log, and then I had to redirect the output of the background process to /dev/null or the deployment fails. Commented Dec 22, 2017 at 13:04

1 Answer 1

3

AfterInstall: AfterInstall script contains the tasks need to be executed after installing the Application.

Example of BeforeInstall script:

#!/bin/bash cd /home/ubuntu/production/weone-backend sudo chown -R ubuntu:ubuntu /home/ubuntu/production sudo NODE_ENV=production nohup nodejs app.js > /dev/null 2> /dev/null < /dev/null & 

In the above script, we are changing the ownership of our application folder & starting application process.

Note: Use “/dev/null 2> /dev/null < /dev/null &” to get out of nohup shell automatically, else your CodeDeploy would get stuck at AfterInstall event.

https://www.oodlestechnologies.com/blogs/AWS-CodeDeploy

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.