即使使用了永久JS,Node JS应用也会崩溃 [英] Node JS app crashing itself even after using forever JS
问题描述
我只是讨厌看到我的服务器每次打开和关闭都关闭。.每当我醒来时,它就关闭了。每次我必须使用SSH然后运行
I am just tired of seeing my server goes down every time off and on.. Whenever I wake up it is down. Every time I have to go to SSH and then run
forever restartall
重新启动我的节点应用程序:(
to restart my node app :(
我一直看着日志文件,它说这
I looked into the log file of forever and it says this
error: Forever detected script was killed by signal: SIGKILL
error: Script restart attempt #1
我绝对不知道为什么会这样。
I have absolutely no idea why is this happening.
我甚至每隔50分钟运行一次cron作业,以自动重启节点js,以防其自身崩溃
I am even running a cron job after every 50 minutes to auto restart node js in case it went down itself
0,50 * * * * * forever restartall
我的应用程序在Ubuntu EC2 AWS上运行,我使用以下命令以便永远使用我的节点应用程序:
My app is running on Ubuntu EC2 AWS. And I use the following command to start my node app using forever:
forever -m5000 -w start index.js
此外,这是最近发生的一些系统日志快照,因为这是最近发生的
Also, here are some recent snap of syslog since this happened recently
Jun 1 12:50:01 ip-172-31-28-35 CRON[25924]: (ubuntu) CMD (forever restartall)
Jun 1 12:50:01 ip-172-31-28-35 CRON[25923]: (CRON) info (No MTA installed, discarding output)
Jun 1 13:00:01 ip-172-31-28-35 CRON[25930]: (ubuntu) CMD (forever restartall)
Jun 1 13:00:01 ip-172-31-28-35 CRON[25929]: (CRON) info (No MTA installed, discarding output)
Jun 1 13:05:50 ip-172-31-28-35 dhclient: DHCPREQUEST of 172.31.28.35 on eth0 to 172.31.16.1 port 67 (xid=0x58e67545)
Jun 1 13:05:50 ip-172-31-28-35 dhclient: DHCPACK of 172.31.28.35 from 172.31.16.1
Jun 1 13:05:50 ip-172-31-28-35 dhclient: bound to 172.31.28.35 -- renewal in 1415 seconds.
Jun 1 13:09:01 ip-172-31-28-35 CRON[26000]: (root) CMD ( [ -x /usr/lib/php5/maxlifetime ] && [ -x /usr/lib/php5/sessionclean ] && [ -d /var/lib/php5 ] && /usr/lib/php5/sessionclean /var/lib/php5 $(/usr/lib/php5/maxlifetime))
Jun 1 13:17:01 ip-172-31-28-35 CRON[26016]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jun 1 13:20:01 ip-172-31-28-35 CRON[26023]: (ubuntu) CMD (/home/ubuntu/cron/serv.sh)
Jun 1 13:20:01 ip-172-31-28-35 CRON[26022]: (CRON) info (No MTA installed, discarding output)
Jun 1 13:29:25 ip-172-31-28-35 dhclient: DHCPREQUEST of 172.31.28.35 on eth0 to 172.31.16.1 port 67 (xid=0x58e67545)
Jun 1 13:29:25 ip-172-31-28-35 dhclient: DHCPACK of 172.31.28.35 from 172.31.16.1
Jun 1 13:29:25 ip-172-31-28-35 dhclient: bound to 172.31.28.35 -- renewal in 1560 seconds.
Jun 1 13:34:39 ip-172-31-28-35 crontab[26289]: (ubuntu) LIST (ubuntu)
这是我的Ubuntu终端上的 free-h
命令的快照:
Here is the snapshot of the free-h
command on my terminal of Ubuntu:
,这是 df -h
命令的快照:
and here is snapshot of df -h
command:
有什么方法可以解决这个问题,并诊断为什么我的应用会崩溃?
Is there any way to fix this and diagnose why my app crashes itself?
以下建议后的最新编辑和日志:
卸载MySQL。
添加了SWAP。
我添加了未捕获的异常代码
现在,当我今天醒来时,服务器再次关闭,这是我永远的日志 http://kl1p.com/AI01 和这些是崩溃和系统日志截图 https://snag.gy/WMzqL0.jpg
https:/ /snag.gy/0wG8Dx.jpg
LATEST EDIT AND LOGS AFTER FOLLOWING SUGGESTIONS: Uninstalled MySQL. Added SWAP. I added the uncaught exception code Now when I woke up today the server was again down and this is my forever log http://kl1p.com/AI01 and these r my free-h just after the crash and syslog screenshot https://snag.gy/WMzqL0.jpg https://snag.gy/0wG8Dx.jpg
任何人都可以帮助导致RAM充分使用的原因以及Node JS导致错误的原因,以及如何修复它们?
Can anyone please help what is causing the RAM to go fully used and why Node JS is causing errors, how to fix them?
推荐答案
我怀疑内存有问题。蛮力强迫永远
重新启动(cron等)只会掩盖真正的问题。
I suspect memory issues. Brute forcing forever
restarts (cron's etc) will only mask the real issue.
将此添加到您的代码中:
Add this to your code:
process.on('uncaughtException', function (err) {
console.log("Uncaught Exception:", err);
process.exit(1); // This is VITAL. Don't swallow the err and try to continue.
});
这将允许您开始诊断导致节点服务器故障的过程。
This will allow you to begin the process of diagnosing what is causing your node server to fail.
这篇关于即使使用了永久JS,Node JS应用也会崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!