I'm trying to configure MongoDB in OS X Mountain Lion. I've installed with Homebrew; I have followed lots of tutorials, but I have got an issue which I haven't been able to solved.
The issue is related with launchctl unload
and launchctl load
commands. My homebrew.mxcl.mongodb.plist
is located at /usr/local/Cellar/mongodb/2.4.6/
and it contains the following code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>homebrew.mxcl.mongodb</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/Cellar/mongodb/2.4.6/mongod</string>
<string>run</string>
<string>--config</string>
<string>/usr/local/Cellar/mongodb/2.4.6/mongod.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<false/>
<key>WorkingDirectory</key>
<string>/usr/local</string>
<key>StandardErrorPath</key>
<string>/usr/local/Cellar/mongodb/2.4.6/data/log/mongod.log</string>
<key>StandardOutPath</key>
<string>/usr/local/Cellar/mongodb/2.4.6/data/log/mongod.log</string>
<key>HardResourceLimits</key>
<dict>
<key>NumberOfFiles</key>
<integer>1024</integer>
</dict>
<key>SoftResourceLimits</key>
<dict>
<key>NumberOfFiles</key>
<integer>1024</integer>
</dict>
</dict>
</plist>
If I executed sudo launchctl load -w /usr/local/Cellar/mongodb/2.4.6/homebrew.mxcl.mongodb.plist
, in http://localhost:28017/
appears MongoDB's http diagnostic access
information. But if I execute sudo launchctl unload -w /usr/local/Cellar/mongodb/2.4.6/homebrew.mxcl.mongodb.plist
does not disconnected and appears the same in the http://localhost:28017/
url.
To shutdown Mongo I've need the following commands:
use admin
db.shutdownServer()
How can I do to shutdown Mongo automatically with launchctl unload
command?
Best Answer
I tested this, first I installed MongoDB 2.4.6 with brew, and then used launchctl to load and unload. In my testing, it sends a SIGTERM to the mongod process which then shuts down as expected. Here are the commands I used as well as the logs for the
mongod
process:Commands:
Logs:
I did this several times to confirm the behavior. In Chrome at least the status page no longer responds and I receive an error (as expected) once it has been shut down.
The only difference between what I am doing and what you have posted is that I am not using
sudo
(in fact it refuses to load or unload due to dubious ownership of the file). So, I changed the ownership of the plist file to root and triedsudo
with the same results.The only way I was able to recreate a failure to unload was as follows:
sudo launchctl
(root is the owner of the plist file)sudo
This fails with an error however:
Note: Subsequently changing the ownership back to the regular user made the unload successful
Similarly, this also produces the same error:
sudo
(regular user owns the plist file)I was unable to recreate the silent failure you seem to be having with any of the various combinations I tried.
Some information gathering tips which may give you a clue:
launchctl list | grep mongodb
? (it should list something like13340 - homebrew.mxcl.mongodb