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
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 Jul 30 '12 at 11:47
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.
answered Mar 30 at 11:49