I have a node.js application and I use GNU Screen to keep the session alive when I log out from the server. Every now and then the app is down and I need to start it again. I guess it is simply because the server rebooted. Is there a way to lunch the app whenever the server reboots? Maybe still using GNU Screen so that I can get back to the running process? Is what adviced here still the best approach? If so, is this script the easiest way to do so? Thanks! asked 01 Oct '12, 08:34 gabon |
Yes the best approach is with a bash script that is execute via cron at a set interval:
answered 01 Oct '12, 09:55 timg ♦♦ I am using Forever to start node.js app Below is a comment on hacksparrows cron script: "This also means the script will restart the app whenever it’s not running, even if Forever has just noticed it’s dead and is about to do the same thing.... Why not just write an init script for Upstart, systemd, or whaterver your server uses? Then you can also make sure it doesn’t try to launch the app before all dependencies are up." What does Webfaction use? Upstart? sytemd? And how do we write the script?
(11 Aug '13, 21:58)
skyrack
How you decide to keep your apps online is up to you, you can write a script or use an app designed for it. We don't use anything, we have monitor scripts which warn us when things are down and we manually start them.
(11 Aug '13, 23:18)
johns
Just to expand on this, the advice you're referring to (systemd) is for system services, not userspace applications. For that, one simple way is setting the watchdog script as tim suggests. I personally prefer this approach: http://community.webfaction.com/questions/6157/watchdog-script-to-keep-process-running-with-cron Cron does support "
(11 Aug '13, 23:48)
ryans ♦♦
|