pm2中崩溃后重新启动node.js [英] Restart node.js after crash in pm2
问题描述
根据此问题,pm2应该重新启动崩溃的应用程序.
According to this question, pm2 should restart crashed applications.
当我的应用程序崩溃时,什么都没有发生,并且pm2 list
中缺少该过程.我必须以某种方式激活自动重启选项"吗?
When my application crashes nothing happens and the process is missing from pm2 list
. Do I have to somehow activate an 'auto restart option'?
我正在使用:
- pm2 v0.12.3
- 节点v0.11.14
- Amazon Linux
推荐答案
尝试使用PM2作为监视Node.js应用程序的唯一方法的效果很差.最后,我采用的方法是使用 Monit 来监视应用程序过程并在使用monit
配置脚本来执行startOrRestart
或stop
的过程.例如,在monitrc
文件中:
I've had poor results trying to use PM2 as the sole means by which to monitor my Node.js applications. In the end the approach I took was to use to Monit to monitor the application process and use pm2
within the monit
configuration script to startOrRestart
or stop
the process. For example, in a monitrc
file:
check process node_app matching /home/webapps/node_app/app.js
start program = "/bin/bash -lc 'cd /home/webapps/node_app && PM2_HOME=/home/webapps/.pm2 /usr/bin/pm2 startOrRestart processes.json'"
stop program = "/bin/bash -lc 'cd /home/webapps/node_app && PM2_HOME=/home/webapps/.pm2 /usr/bin/pm2 stop processes.json'"
check process node_app matching /home/webapps/node_app/app.js
start program = "/bin/bash -lc 'cd /home/webapps/node_app && PM2_HOME=/home/webapps/.pm2 /usr/bin/pm2 startOrRestart processes.json'"
stop program = "/bin/bash -lc 'cd /home/webapps/node_app && PM2_HOME=/home/webapps/.pm2 /usr/bin/pm2 stop processes.json'"
Not only does this allow you to "watch the watcher" it helps as a work-around for the persistent PM2 fails to restart applications after a reboot bug.
这篇关于pm2中崩溃后重新启动node.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!