Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

start mongodb and return to terminal

Tags:

mongodb

centos

I can start mongodb on terminal via command

./mongod

It starts the mongodb server and then display me information that server is running on this port. but It does not give my terminal back. How can I start mongodb and can get terminal back so mongodb is running the background.

Also how to shutdown if its running in background

like image 591
coure2011 Avatar asked Jan 11 '12 15:01

coure2011


People also ask

How do I start MongoDB in terminal?

To open up the MongoDB shell, run the mongo command from your server prompt. By default, the mongo command opens a shell connected to a locally-installed MongoDB instance running on port 27017 . Try running the mongo command with no additional parameters: mongo.

How do I start MongoDB?

You can start MongoDB from a command line by issuing the mongod command and specifying options. For a list of options, see the mongod reference. MongoDB can also run as a Windows service. For details, see Start MongoDB Community Edition as a Windows Service.


1 Answers

Use

./mongod --fork

or

./mongod &

To shutdown you have to send it a TERM signal.

ps aux | grep mongod - to find a PID

kill -TERM PID - send it a TERM signal, and using the first example we can use the PID file:

kill -TERM $(cat /var/run/mongodb/mongod.pid)

Also you can shut it down from the shell.

$ ./mongo
> use admin
> db.shutdownServer()

--

And another method:

./mongod --fork --pidfilepath /var/run/mongodb/mongod.pid

then (please notice the ticks around the cat)

kill -9 `cat /var/run/mongodb/mongod.pid`
like image 171
Sergio Tulentsev Avatar answered Oct 09 '22 11:10

Sergio Tulentsev