MongoDB on startup for Mac OSX

Discussion in 'Server/Backend related tutorials' started by princess_affair, Oct 10, 2012.

  1. princess_affair

    princess_affair Level 1 Regular Member

    Here's the steps to start your MongoDB every time you switch on your Mac machine.

    Step1: Save the below contents into /Library/LaunchDaemons/org.mongo.mongod.plist

    Code:
    <?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>/opt/local/bin/mongod</string>
      <string>--dbpath</string>
      <string>/opt/local/var/db/mongodb</string>
      <string>--logpath</string>
      <string>/opt/local/var/log/mongodb.log</string>
     </array>
    </dict>
    </plist>
    Step2: Create the log file and DB directory

    sudo chown root:wheel /Library/LaunchDaemons/org.mongo.mongod.plist

    Code:
    sudo touch /opt/local/var/log/mongodb.log
    sudo mkdir -p /opt/local/var/db/mongodb 

    Step3: Run the following commands in terminal to load the file into launchctl

    Code:
    sudo launchctl load /Library/LaunchDaemons/org.mongo.mongod.plist 
    sudo launchctl start org.mongo.mongod
     
  2. This was such an amazing thread.
     

Share This Page