Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
594 views
in Technique[技术] by (71.8m points)

macos - What's a clean way to stop mongod on Mac OS X?

i'm running mongo 1.8.2 and trying to see how to cleanly shut it down on Mac.

on our ubuntu servers i can shutdown 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' shutdown but when i ps -ef | grep mongo it shows me an active process. also, i can still open a mongo shell and query my dbs like it was never shutdown.

the output from my db.shutdownServer() locally is:

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 i can just kill the process but i'd like to do it more cleanly.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It's probably because launchctl is managing your mongod instance. If you want to start and shutdown mongod instance, unload that first:

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

Then start 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() would work just fine.

Added Feb 22 2014:

If you have mongodb installed via homebrew, homebrew actually has a handy brew services command. To show current running services:

brew services list

To start mongodb:

brew services start mongodb-community

To stop mongodb if it's already running:

brew services stop mongodb-community

Update*

As edufinn pointed out in the comment, brew services is now available as user-defined command and can be installed with following command: brew tap gapple/services.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...