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

Code Deploy ApplicationStart gets stuck on pending using node


Hi I'm new to using Code Deploy. I am trying to launch a node application. I have setup.sh, start.sh and app.js in my root directory.

This is my appspec.yml file

version: 0.0
os: linux
files:
 - source: /
   destination: /
hooks:
  Install:
    - location: setup.sh
      timeout: 3600
  ApplicationStart:
    - location: start.sh
      timeout: 3600

setup.sh

yum -y install nodejs npm --enablerepo=epel
npm install

start.sh

node /app.js

app.js (just a basic dummy server)

var express = require("express");
var app = express();

app.get("/",function(req,res) {
    res.send("Hello world")
})


var server = app.listen(8080,function() {
    console.log("Listening at " + server.address().address + ": " + server.address().port);
});

The Install step successfully completes, but Code Deploy gets stuck on pending when it does the ApplicationStart step.

I'm pretty sure it's because the app.js program runs continously, so how is CodeDeploy supposed to know that it's working and move on?


Solution

  • The command node /app.js does not run in background but in foreground, therefor the start.sh script is never finished.

    See this thread for more info about running node in background Node.js as a background service