使用Homebrew'Services'命令需要帮助


9

我最近使用自制软件安装了MongoDB。网上的一些文章建议使用以下命令启动mongo,

brew services start mongo

但是,当我使用此命令时,我收到以下消息,

Error: Unknown command: services

我试着在网上搜索这个问题。但到目前为止没有运气。这可能是什么问题?我在他们的网站上指定了自制软件。为什么这个功能对我不起作用?

手册页没有关于'services'命令的信息。

Answers:


8

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答案


2

它现在是外部的:

brew tap homebrew/services

brew services installbrew services install现在工作。


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.