MongoDB Mac OS X Mountain Lion Launchctl Item
Configure MongoDB to start when Mac OSX system boots.
This guide assumes you've installed mongo using MacPorts like so:
sudo port install mongo
Mongo daemon location is assumed to be
If you download mongo directly, you need to copy all files inside the bin directory to /opt/local/bin as root. Once you do that, the rest of this guide will apply to you.
Create the DB directory and a log file:
sudo mkdir -p /opt/local/var/db/mongodb sudo mkdir -p /opt/local/var/log/ sudo touch /opt/local/var/log/mongodb.log
Create a configuration file:
sudo mkdir -p /opt/local/etc/mongodb sudo cp mongod.conf /opt/local/etc/mongodb/
More on configuration file: http://www.mongodb.org/display/DOCS/File+Based+Configuration
These locations were chosen because that is how most of the other stuff like mysql and redis gets installed.
Install/Reinstall Launchctl Item:
sudo cp org.mongo.mongod.plist /System/Library/LaunchDaemons/. sudo chown root:wheel /System/Library/LaunchDaemons/org.mongo.mongod.plist sudo launchctl load /System/Library/LaunchDaemons/org.mongo.mongod.plist sudo launchctl start org.mongo.mongod`
All of the above commands wrapped into an install script for convenience
This script is safe to run even if mongod is already installed
If your paths are different, you'll need to manually change both the plist file and install script
Install from HomeBrew
brew install mongodb
If you would prefer to install a mac StartupItem (instead of Launchctl item) use mongodb-mac-startup
Idea for this was borrowed from an article on "Cupcake With Sprinkles" blog
Tested with Mongo 2.0.7 and Mac 10.8.1 (Mountain Lion) on 1 Sep 2012