|
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? |
|
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. 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. |
|
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. |
|
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. |