MongoDB Startup Item for Mac OS X Snow Leopard
Save the following as /Library/LaunchDaemons/org.mongo.mongod.plist
<?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>org.mongo.mongod</string>
<key>RunAtLoad</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/mongod</string>
<string>--dbpath</string>
<string>/var/lib/mongodb/</string>
<string>--logpath</string>
<string>/var/log/mongodb.log</string>
</array>
</dict>
</plist>
You will need to create a file for the log and a directory for the database.
sudo touch /var/log/mongodb.log
sudo mkdir /var/lib/mongodb
And in a bash session, run the following:
sudo chown root:wheel /Library/LaunchDaemons/org.mongo.mongod.plist
sudo launchctl load /Library/LaunchDaemons/org.mongo.mongod.plist
sudo launchctl start org.mongo.mongod
Comments
Darragh
Outstanding. Second time in two days I've been to this page! Much appreciated :)
colin
thanks, this works just fine! is it somehow possible to define the user which runs the mongod service?
Mike
Thanks man - you rock! You've saved me minutes a day.
Jamal
Thanks a lot.
Kevin
Thanks for the post. This is exactly what I was looking for, however I cannot seem to get it to work. When I execute: sudo launchctl start org.mongo.mongod.plist I get the error message: launchctl start error: No such process I can start the server normally from other directories, but this doesn't work either: MyMac:LaunchDaemons kevin$ ./usr/local/bin/mongod Permissions problem? Looks like it cant see the mongod process from: /Library/StartupItems/LaunchDaemons
Hunter Ford
Thanks Michael! You're absolutely right, and I have updated the posting.
Michael Pabst
s/StartupItems/LaunchDaemons, my bad
Michael Pabst
It sounds like you should change the location of the PList file to /Library/StartupItems: "The /System/Library/StartupItems directory is reserved for startup items that ship with Mac OS X. All other startup items should be placed in the /Library/StartupItems directory. Note that this directory does not exist by default and may need to be created during installation of the startup item." - http://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPSystemStartup/Articles/StartupItems.html
Aaron
Same here, thanks a ton!
Aaron White
Exactly what I need, thanks for posting this!