What are the advantages and disadvantages of using the upstart script or forever script in a context of running node.js scripts ??
Asked Answered
V

2

9

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 ?

Vichyssoise answered 20/3, 2012 at 18:43 Comment(1)
+1 Not sure why this question is getting more love! I found it very helpful.Ignitron
L
8

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
Lapstrake answered 20/3, 2012 at 18:54 Comment(5)
What if you have few node processes managed by forever and want to restart one of them?Luxate
According to the documentation on forever, you specify the script you want to start/stop/restart as a daemon, so you'd just list it's name. I don't know what you'd need to do if two scripts have the exact same name.Lapstrake
Thanks for explanation. Previously it was number of instance as far as I remember. Both solutions wouln't work in real world :( So, I going to continue using upstart, it is awesome tool.Luxate
Also that bash script has much less chance of failing due to a bug. IMHO the top of a supervisor tree should always be a fairly simple bash script like the one shown here, or using /proc to detect whether a process is still running.Pressmark
Instead of a minimal bash script, you can use a minimal upstart config: #!upstart respawn start on runlevel [2345] exec /usr/bin/node /path/to/myScript.js , and it will be safer and also start on system reboot.Working
D
5

Just to correct a misleading statement in the accepted answer...it is not true that upstart is an Ubuntu-only technology. 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

With that, I think it is a much more compelling solution.

Denomination answered 22/3, 2012 at 16:16 Comment(2)
Just noticed this. RedHat is ditching Upstart for SystemD, so I think my point stands.Lapstrake
Debian also decided to standardize on systemd (all lowercase, please) and it seems likely - according to statements by Shuttleworth - that Ubuntu will follow suit, post 14.04Working

© 2022 - 2024 — McMap. All rights reserved.