4

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?

4

2 回答 2

5

CodeDeploy 代理正在等待它启动的脚本返回退出代码并关闭stdoutstderr. 要在后台启动进程并将其与主机代理分离,以便它可以作为守护进程运行,请尝试:

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

注意:您需要修改您的程序以写入日志文件而不是控制台,因为守护程序通常没有可写入的控制台(就像在这个版本中一样)。

在此处查看官方文档:http: //docs.aws.amazon.com/codedeploy/latest/userguide/troubleshooting.html#troubleshooting-long-running-processes

于 2015-10-07T17:14:52.353 回答
2

该命令node /app.js不在后台运行,而是在前台运行,因此 start.sh 脚本永远不会完成。

有关在后台Node.js 作为后台服务运行节点的更多信息,请参阅此线程

于 2015-10-07T09:50:27.257 回答