简体   繁体   English

NodeJS-让我的应用程序永远运行

[英]NodeJS - Keep my App running with Forever

Currently, I have a NodeJS service running on my server. 当前,我的服务器上运行着NodeJS服务。 It provides a RestAPI thanks to HAPI.JS 由于HAPI.JS,它提供了RestAPI

This service run permanently with forever executed in upstart script but I got some trouble. 该服务永久运行,并且永远新贵脚本中执行,但遇到了一些麻烦。

Sometimes, the service have an error like this : 有时,服务会出现如下错误:

Debug: internal, implementation, error 
    TypeError: Uncaught error: Cannot call method 'replace' of undefined....

At this moment, server is completly down and never restart :( 此时,服务器已完全关闭,再也不会重启:(

I need a 100% stable service that why I have to restart it when an error appears. 我需要100%稳定的服务,这就是为什么我必须在出现错误时重新启动它。

My Question : 我的问题 :

How can I restart NodeJS Service with forever when errors occured ? 发生错误时,如何永久永久重启NodeJS服务?

Run you app with pm2 instead of forever. 使用pm2而不是永远运行您的应用程序。 Pm2 will restart the node server even after uncaught exceptions. 即使未捕获异常,Pm2也会重新启动节点服务器。

If the process fails on startup then it won't restart automatically. 如果该过程在启动时失败,则不会自动重新启动。 You can configure the minimum uptime --minUptime flag. 您可以配置最小正常运行时间--minUptime标志。

You can then use the --watch flag to watch for changes of the fix. 然后,您可以使用--watch标志来监视修订的更改。

However, the specific error you're receiving wouldn't normally stop the Hapi process which would suggest this isn't a forever issue. 但是,您收到的特定错误通常不会停止Hapi进程,这表明这不是forever问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM