Hunter Ford Hunter Ford

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

Downloads


Comments

  • Pete Storey

    I had a problem with this, because the plist had a permissions issue. You seem to need to have the command: sudo launchctl load -w /Library/LaunchDaemons/org.mongo.mongod.plist to make it work (-w setting to run in the wheel group).
  • Stuart Larsen

    thanks you!
  • The Apotek

    I guess the xml in my previous comment was stripped out. I'll try again. &lt;key&gt;SoftResourceLimits&lt;/key&gt; &lt;dict&gt; &lt;key&gt;NumberOfFiles&lt;/key&gt; &lt;integer&gt;1024&lt;/integer&gt; &lt;key&gt;NumberOfProcesses&lt;/key&gt; &lt;integer&gt;512&lt;/integer&gt; &lt;/dict&gt;
  • The Apotek

    Mongo requires more resources than the default Mac OS X soft limits allow. You will get warning about not enough access to open files and processes. To fix this, add a section like this to the .plist file: SoftResourceLimits NumberOfFiles 1024 NumberOfProcesses 512
  • 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!