简体   繁体   English

在运行node.js脚本的上下文中使用upstart脚本或forever脚本有哪些优点和缺点?

[英]What are the advantages and disadvantages of using the upstart script or forever script in a context of running node.js scripts ??

I am a node.js developer. 我是node.js开发人员。 I use Amazon ec2 to deploy my node.js apps. 我使用Amazon ec2来部署我的node.js应用程序。

I want to have my node.js service running permanently - restarted if it fails for any reason. 我希望我的node.js服务永久运行 - 如果由于任何原因失败,则重新启动。

I came across 2 tools . 我遇到了两个工具。 Forever and Upstart 永远新贵

Is there any advantages of using one over the other ? 使用一个优于另一个有什么好处吗?

Is there any other tool which is better ? 还有其他更好的工具吗?

Upstart is a system service controller, similar to SysV Init and will start/stop/restart essentially any service registered for it, Node.js-based or not, and it will also automatically start services on system start for you. Upstart是一个系统服务控制器,类似于SysV Init,它将启动/停止/重启基本上为其注册的任何服务,基于Node.js还是不启动,它也会自动启动系统启动服务。 But Upstart is essentially specific to Ubuntu, and Upstart-specific services won't run on other Linux distros. 但Upstart本质上是针对Ubuntu的,而Upstart特定的服务不会在其他Linux发行版上运行。

Upstart has a SysV Init compatibility layer that you could target,instead, to maintain as broad of a compatibility layer as possible. Upstart有一个SysV Init兼容层,您可以将其作为目标,以保持尽可能广泛的兼容性层。

Forever is a Node.js application that monitors and restarts other Node.js applications as needed, and as defined by its configuration JSON. Forever是一个Node.js应用程序,它根据需要监视并重新启动其他Node.js应用程序,并由其配置JSON定义。 Lots of options and fine-grained control over your service without the effort that would be needed to duplicate it in a custom SysV Init script. 对您的服务进行了大量选项和细粒度控制,而无需在自定义SysV Init脚本中复制它所需的工作量。 However, Forever isn't a system service, so if the server is restarted, you'll have to manually start your forever scripts again. 但是,Forever 不是系统服务,因此如果重新启动服务器,则必须再次手动启动永久脚本。

Beyond that, if all you need is something that will restart your script if/when it crashes, and you don't care about it starting automatically on system start, all you need is a bash script as simple as: 除此之外,如果您需要的只是在崩溃时重启脚本,并且您不关心它在系统启动时自动启动,那么您只需要一个简单的bash脚本:

#!/bin/bash
while true
do
    node ./myScript.js
done

Just to correct a misleading statement in the accepted answer...it is not true that upstart is an Ubuntu-only technology. 只是为了在接受的答案中纠正一个误导性的陈述......新贵是一种仅限Ubuntu的技术。 See: 看到:

https://serverfault.com/questions/291546/centos-6-and-upstart http://searchenterpriselinux.techtarget.com/tip/RHEL-6-ditches-System-V-init-for-Upstart-What-Linux-admins-need-to-know http://en.wikipedia.org/wiki/Upstart#Adoption https://serverfault.com/questions/291546/centos-6-and-upstart http://searchenterpriselinux.techtarget.com/tip/RHEL-6-ditches-System-V-init-for-Upstart-What-Linux -admins-need-to-know http://en.wikipedia.org/wiki/Upstart#Adoption

With that, I think it is a much more compelling solution. 有了这个,我认为这是一个更引人注目的解决方案。

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

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