pm2守护进程挂掉是怎么回事?
发布于 8 年前 作者 zstxt1989 14087 次浏览 来自 问答

昨天发生一起严重事故,不知什么原因,pm2挂掉了,所有node项目的服务都挂了。 应该是进程死掉了,手动把所有 node 进程kill掉,然后再一个个pm2 start 重启才恢复。 ps.查看进程还发现一个 pm2 update 一直卡在那。

查看pm2.log发现如下记录

2016-06-30 10:58:39: [PM2][WORKER] Process 6 restarted because it uses 0 memory and has ONLINE status
2016-06-30 10:58:39: Stopping app:cpaapi id:6
2016-06-30 10:58:39: App name:cpaapi id:6 disconnected
2016-06-30 10:58:39: [PM2] Error caught by domain:
Error: spawn /bin/sh EMFILE
	at exports._errnoException (util.js:896:11)
	at Process.ChildProcess._handle.onexit (internal/child_process.js:182:32)
	at onErrorNT (internal/child_process.js:348:16)
	at _combinedTickCallback (internal/process/next_tick.js:74:11)
	at process._tickDomainCallback (internal/process/next_tick.js:122:9)
2016-06-30 10:58:39: [PM2] Trying to update PM2...
2016-06-30 10:58:39: Process with pid 4571 still not killed, retrying...
2016-06-30 10:58:39: Process with pid 4571 still not killed, retrying...
2016-06-30 10:58:39: Process with pid 4571 still not killed, retrying...
2016-06-30 10:58:39: Process with pid 4571 still not killed, retrying...
2016-06-30 10:58:39: Process with pid 4571 still not killed, retrying...
2016-06-30 10:58:39: Process with pid 4571 still not killed, retrying...
2016-06-30 10:58:39: Process with pid 4571 still not killed, retrying...
Be sure to have the latest version by doing `npm install pm2@latest -g` before doing this procedure.
[PM2] Saving current process list...
2016-06-30 10:58:39: Process with pid 4571 still not killed, retrying...
[PM2] Stopping PM2...
[PM2] Applying action deleteProcessId on app [all](ids: 6,8,9,11)
2016-06-30 10:58:39: Stopping app:cpaapi id:6
/usr/local/nvm/versions/node/v6.0.0/lib/node_modules/.pm2_npminstall/pm2/1.1.3/pm2/lib/TreeKill.js:87
	  throw err;
	  ^

Error: spawn /bin/sh EMFILE
	at exports._errnoException (util.js:896:11)
	at Process.ChildProcess._handle.onexit (internal/child_process.js:182:32)
	at exports._errnoException (util.js:896:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:182:32)
at onErrorNT (internal/child_process.js:348:16)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickDomainCallback (internal/process/next_tick.js:122:9)

请教各路大神怎么查找原因以及pm2挂掉怎么自动重启

8 回复

解决了吗,我最近也遇到了,应该是pm2自己挂掉了

最近也遇到pm2无缘无故就不在了,pm2 list什么都没有

npm install -g pm2@next 安装这个比较靠谱,原先的pm2还是有很多问题,包括自定义模块内无法使用api重启

我也遇到过同样的问题 先把进程kill掉 然后在重启的

防止服务挂掉pm2没有自动重启,比如内存溢出的时候可能pm2没有自动重启,建议监听一下exit后,强制process.exit(0)

应该不是PM2自己挂掉的,如果你在用一些云服务器,某些条件下,服务器会主动把你的进程kill掉,如果kill的是pm2,那就没辙了

之前用 forever 发现,一旦有异常,就会重启服务,而且会重复重启,导致服务资源耗尽,也没有pm2 list这样的命令可以方便的查看资源消耗情况。 后来用了pm2 一直蛮好。 主要是自己多关注服务的状态,特别是监听 uncaughtException 这个系统异常的服务,这样的异常系统捕获到了,但是不会释放错误的内存,所以时间长了会发现内存暴增,然后就莫名挂掉,各种问题~

解决了吗,也是莫名就自己停止运行了,导致整天访问不了

回到顶部