Adding MongoDB to Mac OS X Startup

First, create a plist file at /Library/LaunchDaemons/org.mongo.mongod.plist:

sudo vi /Library/LaunchDaemons/org.mongo.mongod.plist

Next, copy/paste the following XML into the file (keep in mind, your paths to mongod and the database may differ… adjust accordingly if need be):

If you haven’t yet, create a file for the log and a directory for the database:

sudo touch /var/log/mongodb.log

sudo mkdir /var/lib/mongodb

From the command line, 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

If you get any of the paths wrong in the plist file, resulting in the following error:

launchctl start error: Bad file descriptor

… you will need to unload the plist file and load it again, like so:

sudo launchctl unload /Library/LaunchDaemons/org.mongo.mongod.plist

sudo launchctl load /Library/LaunchDaemons/org.mongo.mongod.plist

Like this:

Tags: , ,

%d bloggers like this: