Answers:
services
在Homebrew中是一个“隐藏”的命令。brew help
输出中没有一堆它们。它已经,因为没有文档的命令是不会做的,在官方存储库中消失,并成为另一个附加存储库中维护的“外部命令 ”(在这种情况下是一个要点,因为它是如此简单)。
您可以通过运行以下命令将其安装在Homebrew设置中:
> curl -o /usr/local/bin/brew-services.rb https://gist.githubusercontent.com/lwe/766293/raw/75a7907004bbff0eb3b072d1d951be2cfe7e5020/brew-services.rb
> chmod +x /usr/local/bin/brew-services.rb
> brew services help
usage: [sudo] brew services [--help] <command> [<formula>]
Small wrapper around `launchctl` for supported formulas, commands available:
cleanup Get rid of stale services and unused plists
list List all services managed by `brew services`
restart Gracefully restart selected service
start Start selected service
stop Stop selected service
Options, sudo and paths:
sudo When run as root, operates on /Library/LaunchDaemons (run at boot!)
Run at boot: /Library/LaunchDaemons
Run at login: /Users/ian/Library/LaunchAgents
或者,您可以跳过services
并为其创建一个plist文件。例如,创建~/Library/LaunchAgents/org.mongodb.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.mongodb.mongod</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/Cellar/mongodb/2.6.4/bin/mongod</string>
<string>run</string>
<string>--config</string>
<string>/usr/local/Cellar/mongodb/2.6.4/mongod.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<false/>
<key>UserName</key>
<string>{your_username}</string>
<key>WorkingDirectory</key>
<string>/usr/local</string>
<key>StandardErrorPath</key>
<string>/usr/local/var/log/mongodb/output.log</string>
<key>StandardOutPath</key>
<string>/usr/local/var/log/mongodb/output.log</string>
</dict>
</plist>
只需更改{your_username}
为您的实际用户名,然后运行:
launchctl load ~/Library/LaunchAgents/org.mongodb.mongod.plist
用launchd注册plist。您现在可以使用以下命令启动和停止MongoDB:
launchctl start org.mongodb.mongod
launchctl stop org.mongodb.mongod
注意,上面的plist解决方案取自这个出色的Stack Overflow答案。
如果您不想手动修改文件,Theres是MongoDB网站上的一个有用的GUI。
http://blog.mongodb.org/post/28925264384/macosx-preferences-pane-for-mongodb
MongoDB的MacOSX首选项窗格旨在提供一个简单而有效的用户界面来控制本地MongoDB服务器的状态,就像MySQL Preferences Pane一样。