15次重启后pm2 start app.js退出 [英] pm2 start app.js is exiting after 15 restarts

查看:74
本文介绍了15次重启后pm2 start app.js退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

npm start可以很好地启动我的应用程序,但是当我这样做时:

npm start will start my app just fine but when I do:

pm2 start app.js

我得到:

[PM2] Spawning PM2 daemon
[PM2] PM2 Successfully daemonized
[PM2] Process app.js launched
┌──────────┬────┬──────┬──────┬────────┬─────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ pid  │ status │ restart │ uptime │ memory      │ watching │
├──────────┼────┼──────┼──────┼────────┼─────────┼────────┼─────────────┼──────────┤
│ app      │ 0  │ fork │ 4681 │ online │ 0       │ 0s     │ 11.508 MB   │ disabled │
└──────────┴────┴──────┴──────┴────────┴─────────┴────────┴─────────────┴──────────┘
 Use `pm2 show <id|name>` to get more details about an app

在我得到的日志中:

[PM2] Starting streaming logs for [all] process
PM2: 2015-06-04 17:12:37: App name:app id:0 exited with code 0
PM2: 2015-06-04 17:12:37: Starting execution sequence in -fork mode- for app name:app id:0
PM2: 2015-06-04 17:12:37: App name:app id:0 online
PM2: 2015-06-04 17:12:37: App name:app id:0 exited with code 0
PM2: 2015-06-04 17:12:37: Starting execution sequence in -fork mode- for app name:app id:0
PM2: 2015-06-04 17:12:37: App name:app id:0 online
PM2: 2015-06-04 17:12:37: App name:app id:0 exited with code 0
PM2: 2015-06-04 17:12:37: Starting execution sequence in -fork mode- for app name:app id:0
PM2: 2015-06-04 17:12:37: App name:app id:0 online
PM2: 2015-06-04 17:12:38: App name:app id:0 exited with code 0
PM2: 2015-06-04 17:12:38: Starting execution sequence in -fork mode- for app name:app id:0
PM2: 2015-06-04 17:12:38: App name:app id:0 online
PM2: 2015-06-04 17:12:38: App name:app id:0 exited with code 0
PM2: 2015-06-04 17:12:38: Starting execution sequence in -fork mode- for app name:app id:0
PM2: 2015-06-04 17:12:38: App name:app id:0 online
PM2: 2015-06-04 17:12:39: App name:app id:0 exited with code 0
PM2: 2015-06-04 17:12:39: Starting execution sequence in -fork mode- for app name:app id:0
PM2: 2015-06-04 17:12:39: App name:app id:0 online
PM2: 2015-06-04 17:12:39: App name:app id:0 exited with code 0
PM2: 2015-06-04 17:12:39: Script /home/user/app/app.js had too many unstable restarts (15). Stopped. "errored"

这是我的package.json:

here is my package.json:

  1 {
  2   "name": "app",
  3   "version": "0.0.0",
  4   "private": true,
  5   "scripts": {
  6     "start": "node ./bin/www"
  7   },
  8   "dependencies": {
  9     "body-parser": "~1.12.4",
 10     "cookie-parser": "~1.3.5",
 11     "debug": "~2.2.0",
 12     "express": "~4.12.4",
 13     "jade": "~1.9.2",
 14     "morgan": "~1.5.3",
 15     "serve-favicon": "~2.2.1",
 16     "stylus": "0.42.3"
 17   }
 18 }

节点版本:v0.10.38pm2版本:0.12.15

node version: v0.10.38 pm2 version: 0.12.15

我该如何调试呢?我不确定为什么会失败,还有其他地方需要检查吗?我的app.js文件?

How do I even debug this? I am not sure why it's failing, is there some other place I need to check? My app.js file?

推荐答案

首先,我将尝试 node ./bin/www 并确保其正常工作.

First, I'd try node ./bin/www and just make sure that works correctly.

我不确定弄清楚这一点的官方"方式是什么,但这应该可行:
您可以将未捕获的异常处理程序放入代码中,该处理程序可以简单地写入文件或执行其他操作.

I'm not sure what the "official" way to figure this out is but this should work:
You could put an uncaught exception handler into your code which simply writes to a file or do something else.

process.on('uncaughtException', function(err) {
    console.log('Caught exception: ' + err);
    throw err;
});


修改:根据您的评论,您遇到问题的原因是因为 app.js 不是您的应用程序中真正的入口点.真正的入口点是 ./bin/www


Based on your comment the reason you're having issues is because app.js is not the real entry point in your application. The real entry point is ./bin/www

因此,您需要告诉PM2启动该文件,而不是像这样的 app.js :
pm2 start ./bin/www

So you need to tell PM2 to start that file rather than app.js like this:
pm2 start ./bin/www

这篇关于15次重启后pm2 start app.js退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆