Code Deploy ApplicationStart gets stuck on pending using node

▼魔方 西西 提交于 2019-12-21 17:37:39

问题


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?


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/32944933/code-deploy-applicationstart-gets-stuck-on-pending-using-node

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!