6

I am running MongoDB on Webfaction as a database of a Django app . Problem is I have to keep my SSH terminal session open and use this syntax to keep running MongoDB .

mongod --dbpath ~/webapps/mongo_db/mongodb/ --port 31706

As soon as I close my terminal the connection to database dies . What is the solution to keep mongodb running always on server ?

flaudre
  • 2,358
  • 1
  • 27
  • 45
peter
  • 63
  • 3
  • `sudo service mongodb status` ? – itzMEonTV Feb 15 '15 at 10:54
  • this is an app runnuing on Webfaction server , when I do service mongodb status it gives me this error : mongodb: unrecognized service – peter Feb 15 '15 at 11:44
  • then check `mongod service` via `sudo service mongod status` – itzMEonTV Feb 15 '15 at 11:47
  • You installed from source which by default does not provide a init script. Instead you should follow the install instructions here http://docs.mongodb.org/manual/installation/ if you are unsure how to make an init script, the packages come pre-loaded with one – Sammaye Feb 15 '15 at 12:33

2 Answers2

7

WebFaction is a shared host, so you can't run mongod as a system service.

Instead, use the --fork option when starting mongod, like so:

mongod --dbpath ~/webapps/mongo_db/mongodb/ --port 31706 --fork \
       --logpath $HOME/logs/user/mongo_db.log

When you need to stop it, run:

mongod --dbpath ~/webapps/mongo_db/mongodb/ --port 31706 --shutdown

Hope that helps!

Sean F
  • 817
  • 9
  • 20
  • If you were running a program that doesn't have a `--fork` option, you could also use `nohup` – jpaugh Jul 18 '15 at 03:03
0

I could solve it with :

mongod --dbpath ~/webapps/mongo_db/mongodb/ --port 31706 --fork \ --logpath $HOME/logs/user/mongo_db.log

Also we can put a cron task to check it time to time .

peter
  • 63
  • 3