Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 472
Greg Hornby Avatar asked Mar 15 '23 14:03

Greg Hornby


1 Answers

The CodeDeploy agent is waiting for the script it launched to return an exit code and to close stdout and stderr. To start a process in the background and detach it from the host agent so it can run as a daemon, try:

node /app.js > /dev/null 2> /dev/null < /dev/null &

Note: you'll want to modify your program to write to a log file instead of the console, since daemons usually don't have a console to write to (as it is in this version).

See the official docs here: http://docs.aws.amazon.com/codedeploy/latest/userguide/troubleshooting.html#troubleshooting-long-running-processes

like image 51
Jonathan Turpie Avatar answered Mar 17 '23 21:03

Jonathan Turpie