服务器关闭/崩溃时,节点JS自动重启所有永久的JS进程 [英] Node JS auto restart all forever JS process when server goes down / crashes

查看:165
本文介绍了服务器关闭/崩溃时,节点JS自动重启所有永久的JS进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用永远的js来使节点服务器在AWS EC2上保持24/7运行。

I am using forever js to keep my node server running 24/7 on AWS EC2.

我使用此命令

forever start index.js

但是,我注意到有一段时间它随机停止了该过程,并且我的网站关闭了。我必须手动通过ssh进入服务器才能通过以下方式再次运行它:

However, I notice that some time it randomly stops the process and my site goes down. I have to manually ssh into my server to run it again by doing:

forever restartall

然后备份。有什么方法可以定义超时,可以说如果服务器/网站在5秒钟内没有响应200,然后自动重新启动所有永久进程?

And then it goes backup. Is there any way by which I can define a timeout, lets say if the server/website does not respond for 200 in 5 sec, then restart all forever process automatically?

我是新手,如果有人可以举一个例子来说明我的情况,那就太好了。

I am new to this, if any one can give me step by step example for my case, it would be awesome.

推荐答案

弄清楚了。问题是由于我的EC2实例中的可用RAM较少。我将RAM升级到2 GB,到目前为止还没有经历过崩溃。

Figured it out. The problem was due to less RAM available in my EC2 instance. I upgraded RAM to 2 GB and have not experienced the crash so far.

节点也可以产生未捕获的异常错误,但是我的主要问题是由于内存较少。

Node can also make uncaught exception errors but my major problem was due to less memory.

希望这对其他人有帮助。

Hope this helps others.

这篇关于服务器关闭/崩溃时,节点JS自动重启所有永久的JS进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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