What a clean way to stop mongod on mac os x?

I am running mongo 1.8.2 and trying to figure out how to completely disable it on a Mac.

on our ubuntu servers, I can disconnect mongo cleanly from the mongo shell with:

> use admin > db.shutdownServer() 

but on my Mac it does not kill the mongod process. the output shows that it should be "off", but when I ps -ef | grep mongo shows me the active process. In addition, I can still open the mongo shell and request my dbs, like never shutting down.

the output from my db.shutdownServer () locally:

 MongoDB shell version: 1.8.2 connecting to: test > use admin switched to db admin > db.shutdownServer() Tue Dec 13 11:44:21 DBClientCursor::init call() failed Tue Dec 13 11:44:21 query failed : admin.$cmd { shutdown: 1.0 } to: 127.0.0.1 server should be down... Tue Dec 13 11:44:21 trying reconnect to 127.0.0.1 Tue Dec 13 11:44:21 reconnect 127.0.0.1 failed couldn't connect to server 127.0.0.1 Tue Dec 13 11:44:21 Error: error doing query: unknown shell/collection.js:150 

I know that I can just kill the process, but I would like to do it more cleanly.

+55
mongodb macos launchd
Dec 13 '11 at 19:53
source share
6 answers

Probably because launchctll manages your mongod instance. If you want to start and close the mongod instance, first unload it:

 launchctl unload -w ~/Library/LaunchAgents/org.mongodb.mongod.plist 

Then run mongod manually:

 mongod -f path/to/mongod.conf --fork 

You can find your mongod.conf location from ~/Library/LaunchAgents/org.mongodb.mongod.plist .

After that, db.shutdownServer() will work fine.

Added February 22, 2014:

If you have mongodb installed via homebrew, homegrown does have a convenient brew services team. To show current current services:

brew services list

To start mongodb:

brew services start mongodb

To stop mongodb if it is already running:

brew services stop mongodb

Update

As edufinn noted in a comment, brew services now available as a user command and can be installed with the following command: brew tap gapple/services .

+116
Dec 14 '11 at 5:12
source share

If you installed mongodb with homebrew, it will be easier for you:

List of mongo job with launchctl:

 launchctl list | grep mongo 

Stop mongo:

 launchctl stop <job label> 

(For me, this is launchctl stop homebrew.mxcl.mongodb )

Run mongo job:

 launchctl start <job label> 
+21
Feb 13
source share

An easy way is to get the mongodb process id and kill it. Please note that for this do not use kill -9 pid, as this can lead to database corruption.

so 1. get pid mongodb

$ pgrep mongo

you will get pid of mongo, now

$ kill

You can also use kill -15

+11
Feb 17 '16 at 10:16
source share

I prefer to stop the MongoDB server using the port command itself.

 sudo port unload mongodb 

And run it again.

 sudo port load mongodb 
+4
Jan 13 '14 at 23:25
source share

Check out these docs:

http://www.mongodb.org/display/DOCS/Starting+and+Stopping+Mongo#StartingandStoppingMongo-SendingaUnixINTorTERMsignal

If you run it in the terminal, you should be ok with ctrl + 'c' - this will lead to a clean shutdown.

However, if you use launchctll, specific instructions will be indicated for it, which will vary depending on how it was installed.

If you use Homebrew, this will be launchctl stop homebrew.mxcl.mongodb

+3
Dec 13 '11 at 22:52
source share

This is an old question, but I found it when searching.

If you installed with brew , then the solution would actually be as follows:

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist

+2
Oct 04 '15 at 2:11
source share



All Articles