login community faq

Hello,

I have a Node.js app and a MongoDB server that are custom applications listening on their respective ports. Now, everything works fine, but the problem I am having is that I can only run the program while the terminal window is open. I've tried to nohup both the mongoDB app and the node.js app but they still fail when the terminal window is closed. I looked up some info on running mongoDB as a daemon, and used the --fork option when starting the mongoDB server. Still fails when I sign out of a ssh area.

Basically, I how do I get mongoDB to act like the MySQL server -- always running and able to accept new connections? And how do I keep node.js app up and running constantly, ala Apache?

asked Jul 30 '12 at 08:46

IronShah's gravatar image

IronShah
11


Have you taken a look at our docs on MongoDB? There are instructions at the end that say how to run the MongoDB service.

You can also set up a cronjob to start it every 20 minutes or so in case it dies for some reason.

answered Jul 30 '12 at 09:11

todork's gravatar image

todork
10964

Yes, I followed those docs to get the mongo instance installed and running. But the commands they give at the end of that doc are only alive for as long as the ssh session.

(Jul 30 '12 at 09:31) IronShah IronShah's gravatar image

You just need to start the process as a background process to keep it running when you close the window. You can do this by adding a "&" at the end of your command:

1
command &

Alternatively you can use nohup to keep the process running.

answered Jul 30 '12 at 11:47

timg's gravatar image

timg ♦♦
4864

I tried what you said, but when I close out the session, command is dropped. For instance, I nohup the node command like "nohup node app.js &". This should mean that my node webserver will be working when I go to the site. But everything I log out of the SSH session, I get Bad Gateway errors. I'm assuming those errors are because the node server isn't running so nothing is responding to the user when you go the site.

(Jul 30 '12 at 13:49) IronShah IronShah's gravatar image

The "nohup node app.js &" command should work for keeping your application running after closing your ssh session. When you start the application with just with "node app.js" do you receiving any errors. If so then there is another issue, please open a support ticket via https://help.webfaction.com or via the 'Support' menu item at ttps://my.webfaction.com and we can help you find the other issue.

(Jul 30 '12 at 14:09) timg ♦♦ timg's gravatar image

I'm having a similar issue. I can't get mongodb to stick around according to the guide or what's written here. I'm using a crontab instead and writing a ticket for these comments to be clarified.

(Dec 15 '12 at 08:05) ubershmekel ubershmekel's gravatar image

Try:

  • running MongoDB in a 'screen'
  • running mongodb as a background process:

mongodb --fork

you might also wish to log its output:

mongod --fork --logpath $HOME/logs/user/mongod.log

NOTE: the --fork option is available only for v1.1 and up.

More details at

http://www.mongodb.org/display/DOCS/Starting+and+Stopping+Mongo#StartingandStoppingMongo-RunningasaDaemon

Of course, having a cron job that starts MongoDB every XX minutes is a must for a live site, as per my colleague TodorK's suggestion.

answered Dec 15 '12 at 08:28

valentini's gravatar image

valentini ♦♦
1113

edited Dec 15 '12 at 08:30

Screen is actually very good because it holds the terminal for you, allowing you to see logs and messages that your server prints out.

Otherwise, for backgrounding, I prefer the 'at' command instead of nohup, or appending '&'.

For example, I can run mongodb like so:

1
echo "mongod --auth --dbpath ... --port ..." | at

Like screen, the 'at' command takes over the terminal for the mongod process and you can exit your SSH session safely.

Of course, having a cron job to regularly check and restart your service is crucial for a LIVE site.

answered Mar 30 at 11:49

chnrxn's gravatar image

chnrxn
1

Your answer
If you have an answer to the above question, then use the form below. Otherwise, use the appropriate 'add new comment' button above to post your feedback.
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

Tags:

×57
×19
×19
×6
×2

Asked: Jul 30 '12 at 08:46

Seen: 1,377 times

Last updated: Mar 30 at 11:49

Plans & prices    Sign up    Why WebFaction?    Contact us    Affiliate program    Support    Legal    Jobs    Blog    Control panel login
Powered by OSQA
© Copyright 2003-2012 Swarma Limited - WebFaction is a service of Swarma Limited