Skip to content

Instantly share code, notes, and snippets.

@dacodekid
Forked from subfuzion/mongo-autostart-osx.md
Last active September 23, 2015 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dacodekid/719501e85be86f6a9e98 to your computer and use it in GitHub Desktop.
Save dacodekid/719501e85be86f6a9e98 to your computer and use it in GitHub Desktop.
mongo auto start on OS X

Install with Homebrew

brew install mongodb

Set up launchctl to auto start mongod

$ ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents

/usr/local/opt/mongodb/ is a symlink to /usr/local/Cellar/mongodb/x.y.z (e.g., 2.4.9)

Then Edit the 'mongod.conf' file with 'sudo atom /usr/local/etc/mongod.conf' (depending on your db & log location)

systemLog:
    destination: file
    path: ~/Dev/data-mongo/log/mongod.log
    logAppend: true
storage:
    dbPath: ~/Dev/data-mongo/db/
net:
    bindIp: 127.0.0.1

You can use launchctl to start and stop mongod

$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
$ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist

You can also more conveniently use brew to start, stop, and verify service status

$ brew services list | grep mongodb
$ brew services start mongodb
$ brew services stop mongodb

Notes

The default plist provided by homebrew stores the mongod configuration at /usr/local/etc/mongod.conf. This configuration specifies the dbpath to be /usr/local/var/mongodb instead of the default /data/db.

For more about launchctl see:

https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/launchctl.1.html#//apple_ref/doc/man/1/launchctl

http://launchd.info/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment