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 /opt/local/bin/mongod
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.
sudo mkdir -p /opt/local/var/db/mongodb
sudo mkdir -p /opt/local/var/log/
sudo touch /opt/local/var/log/mongodb.log
These locations were chosen because that is how most of the other stuff like mysql and redis gets installed.
sudo cp org.mongo.mongod.plist /System/Library/LaunchDaemons/.
sudo chown root:wheel /System/Library/LaunchDaemons/org.mongo.mongod.plist
sudo launchctl stop org.mongo.mongod
sudo launchctl unload /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
./install.sh
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
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 1.4.2 and Mac 10.6.3 (Snow Leopard) on 4 May 2010