Search code examples
djangomongodbwebfaction

MongoDB instance stops running on Webfaction


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 ?


Solution

  • 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!