Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I just kill mongod to stop mongo?

I am very new at Mongo. I am running mongod as described here in Mac OS X. I am running two mongod processes from the command line. If I need to stop the mongod processes I just execute kill <pid of mongod>. Is it the recommended way to stop mongod?

like image 893
Michael Avatar asked Jan 29 '14 12:01

Michael


People also ask

What is the role of mongod process in MongoDB?

mongod is the primary daemon process for the MongoDB system. It handles data requests, manages data access, and performs background management operations.

What is mongo vs mongod?

mongod is a background process used by MongoDB. The main purpose of mongod is to manage all the MongoDB server tasks. For instance, accepting requests, responding to client, and memory management. mongo is a command line shell that can interact with the client (for example, system administrators and developers).


3 Answers

It finally succeeded (Ubuntu 15.04) with

//1.find process by name:

$ pgrep mongo

1350

//2.kill mongod-process

$ kill 1350
like image 66
Mailis Toompuu Avatar answered Oct 16 '22 21:10

Mailis Toompuu


This is quite late, but I had same problem now, and I found one easy way :

Esan-iMac:~$mongo admin --eval "db.shutdownServer()"

MongoDB shell version: 2.6.4
connecting to: admin
2015-02-19T10:54:22.574+0200 DBClientCursor::init call() failed
server should be down...

It's giving some odd messages, but it works.

And I made alias-command for running it easy.

alias stop-mongo='/opt/mongo/release/bin/mongo admin --eval "db.shutdownServer()"'

This works at least if you start your mongo manually (e.g. with --fork option).

like image 49
Esa Avatar answered Oct 16 '22 22:10

Esa


The accepted answer by Esa is correct. Also, regarding whether using kill is recommended - yes, but with flag -2 or no flag, never use -9. As mentioned in docs.

kill -2 `pgrep mongo`

Alias

alias stopmongo='kill -2 `pgrep mongo`'
like image 20
saurabheights Avatar answered Oct 16 '22 20:10

saurabheights