pm2守护进程挂掉是怎么回事?
昨天发生一起严重事故,不知什么原因,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 回复
之前用 forever 发现,一旦有异常,就会重启服务,而且会重复重启,导致服务资源耗尽,也没有pm2 list这样的命令可以方便的查看资源消耗情况。 后来用了pm2 一直蛮好。 主要是自己多关注服务的状态,特别是监听 uncaughtException 这个系统异常的服务,这样的异常系统捕获到了,但是不会释放错误的内存,所以时间长了会发现内存暴增,然后就莫名挂掉,各种问题~