Via terminal crie o arquivo plist no diretório: /Library/LaunchDaemons/org.mongo.mongod.plist
Coloque o conteúdo abaixo:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
Na linha 11 você configura o local de instalação do seu Mongo, verifique se está no mesmo local padrão.
As vezes ele pode está sendo executado de:
/usr/bin/mongod
Depois precisamos criar o arquivo de log e o diretório onde salvaremos os bancos:
sudo mkdir -p /opt/local/var/db/mongodb sudo mkdir -p /opt/local/var/log/ sudo touch /opt/local/var/log/mongodb.log
Por fim adicione nosso arquivo plist no Launch:
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
Agora ao reiniciar a maquina o Mac irá startar o Mongo automaticamente.
Related links: http://hunterford.me/mongodb-startup-item/
Solução alternativa seria rodar o script feito Andrei Railean: https://github.com/AndreiRailean/MongoDB-OSX-Launchctl