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:
If you have installed mongodb community server via homebrew, then you can do:
brew services list
This will list the current services as below:
Name Status User Plist
mongodb-community started thehaystacker /Users/thehaystacker/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
redis stopped
Then you can restart mongodb by first stopping and restart:
brew services stop mongodb
brew services start mongodb
I prefer to stop the MongoDB server using the port
command itself.
sudo port unload mongodb
And to start it again.
sudo port load mongodb
The solutions provided by others used to work for me but is not working for me anymore, which is as below.
brew services stop mongodb
brew services start mongodb
brew services list
gives
Name Status User Plist
mongodb-community started XXXXXXXXX /Users/XXXXXXXXX/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
So I used mongodb-community
instead of mongodb
which worked for me
brew services stop mongodb-community
brew services start mongodb-community
Check out these docs:
http://www.mongodb.org/display/DOCS/Starting+and+Stopping+Mongo#StartingandStoppingMongo-SendingaUnixINTorTERMsignal
If you started it in a terminal you should be ok with a ctrl + 'c'
-- this will do a clean shutdown.
However, if you are using launchctl there are specific instructions for that which will vary depending on how it was installed.
If you are using Homebrew it would be launchctl stop homebrew.mxcl.mongodb
If the service is running via brew, you can stop it using the following command:
brew services stop mongodb
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 stop 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
.