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 |
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 30 Jul '12, 09:11 todork 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:
Alternatively you can use nohup to keep the process running. answered 30 Jul '12, 11:47 timg ♦♦ 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:
you might also wish to log its output:
NOTE: the --fork option is available only for v1.1 and up. More details at 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 15 Dec '12, 08:28 valentini |
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:
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 30 Mar '13, 11:49 chnrxn |
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 answered 14 Dec '14, 21:24 mogga |
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.
Hi ,
Could you solve this issue ? I have exactly same problem with mongodb . Would be grateful if you help .
Best
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.