WebFaction
Community site: login faq

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
1548
accept rate: 0%

edited 02 Oct '12, 01:13


Yes the best approach is with a bash script that is execute via cron at a set interval:

if [ `ps -u USERNAME | grep -i PROCESS | wc -l` -lt 1 ]
then
    echo "Starting <PROCESS>."
    <enter the command to start your process here>
else
    echo "<PROCESS> is running."
fi
permanent link

answered 01 Oct '12, 09:55

timg ♦♦
1.3k4
accept rate: 30%

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 "@reboot", but I wouldn't use it, instead lowering the delay on the cron command if 2.5 minutes (on average) is too long to have the service down after a reboot. In practice I've never seen this to be a problem.

(11 Aug '13, 23:48) ryans ♦♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×67
×24

question asked: 01 Oct '12, 08:34

question was seen: 6,974 times

last updated: 11 Aug '13, 23:48

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM