Search code examples
node.jsupstart

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. I use Amazon ec2 to deploy my node.js apps.

I want to have my node.js service running permanently - restarted if it fails for any reason.

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 ?


Solution

  • 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. But Upstart is essentially specific to Ubuntu, and Upstart-specific services won't run on other Linux distros.

    Upstart has a SysV Init compatibility layer that you could target,instead, to maintain as broad of a compatibility layer as possible.

    Forever is a Node.js application that monitors and restarts other Node.js applications as needed, and as defined by its configuration 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. However, Forever isn't a system service, so if the server is restarted, you'll have to manually start your forever scripts again.

    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:

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