WebFaction
Community site: login 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 30 Jul '12, 08:46

IronShah
1111
accept rate: 0%

I used this technique to keep MongoDB running and it worked: http://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/

I've also used the node module 'forever' to keep node.js apps running. You may be able to use forever to run the mongod service, would be interested to know if that works.

(11 Jan '15, 01:53) tomdriley

Hi ,

Could you solve this issue ? I have exactly same problem with mongodb . Would be grateful if you help .

Best

(15 Feb '15, 10:44) masnadi

There have been several answers to keeping mongodb running. Perhaps a support ticket is warranted to debug the various answers in this post that you have tried.

(15 Feb '15, 12:09) aaront ♦♦

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.

permanent link

answered 30 Jul '12, 09:11

todork
1.2k4
accept rate: 34%

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.

(30 Jul '12, 09:31) IronShah

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:

command &

Alternatively you can use nohup to keep the process running.

permanent link

answered 30 Jul '12, 11:47

timg ♦♦
1.3k4
accept rate: 30%

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.

(30 Jul '12, 13:49) IronShah

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.

(30 Jul '12, 14:09) timg ♦♦

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.

(15 Dec '12, 08:05) ubershmekel

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.

permanent link

answered 15 Dec '12, 08:28

valentini
2614
accept rate: 28%

edited 15 Dec '12, 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:

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.

permanent link

answered 30 Mar '13, 11:49

chnrxn
11
accept rate: 0%

For whatever reason... I was bored and wrote this... it's a work in progress

https://github.com/mogga/webfaction-meteor

Would love some pull requests to improve on it

permanent link

answered 14 Dec '14, 21:24

mogga
213
accept rate: 0%

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:

×84
×34
×29
×10
×3

question asked: 30 Jul '12, 08:46

question was seen: 11,950 times

last updated: 15 Feb '15, 12:09

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