how to automatically restart a node server?

被刻印的时光 ゝ 提交于 2019-12-21 03:11:02

问题


We are finishing development of a project, the client is already using it but occasionally some errors occur - crashing the server.

I know I could register a service as 'upstart' script on linux, in order to have my node service restart when it crashes.

But our server is running other stuff, so we can't restart it. Well, actually, while writing, I realize I have two questions then:

  • Will 'upstart' work without having to reboot? Something is just whispering yes to me :)
  • If not, what other option would I have to 'respawn' my node server when it crashes?

回答1:


Yes, upstart will restart your process without a reboot.

Also, you should look into forever.




回答2:


PM2 is a Production process manager for Node.js app.




回答3:


If your focus for automatic restart is an always running application, I suggest to use a process manager. Process manager, in general, handles the node process(es if cluster enabled), and is responsible for the process/es execution. PM leans on the operative system: your node app and the OS are not so strinctly chained because the pm is in the middle.

Final trick: put the process manager on upstart.

Here is a complete performance improvement path to follow.

来源:https://stackoverflow.com/questions/16547996/how-to-automatically-restart-a-node-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!