【问题标题】:Homebrew: How to check if a homebrew service is switched on or notHomebrew:如何检查 Homebrew 服务是否已打开
【发布时间】:2021-03-31 07:49:04
【问题描述】:

我使用elasticsearch 实例作为nosql 数据库。这是在 mac os 上使用brew 安装的。

这就是我开始elasticsearch的方式。

brew services start elasticsearch

我想知道是否有 brew 命令(或其他命令)可以让我知道 elasticsearch 实例是否打开。

最终我想运行一个 bash 脚本,它执行以下操作:

If elasticsearch is off:
    Turn on elastiscearch
    Proceed
Else:
    Proceed

【问题讨论】:

    标签: bash shell elasticsearch curl homebrew


    【解决方案1】:

    brew services list 提供服务状态。所以像 brew services list | grep elastiscearch | awk '{ print $2}' 这样的东西应该返回弹性搜索服务的状态,无论是 started 还是 stopped

    【讨论】:

      【解决方案2】:

      只要运行:

      brew services
      

      样本输出

      Name      Status  User Plist
      grafana   started mark /Users/mark/Library/LaunchAgents/homebrew.mxcl.grafana.plist
      influxdb  started mark /Users/mark/Library/LaunchAgents/homebrew.mxcl.influxdb.plist
      mosquitto stopped      
      redis     started mark /Users/mark/Library/LaunchAgents/homebrew.mxcl.redis.plist
      unbound   stopped 
      

      您还可以运行以下命令来获取 homebrew 服务的进程 ID (pid):

      launchctl list | grep homebrew
      
      460 0   homebrew.mxcl.influxdb
      484 0   homebrew.mxcl.grafana
      469 0   homebrew.mxcl.redis
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-30
        • 1970-01-01
        • 1970-01-01
        • 2019-06-06
        • 2012-08-30
        • 2022-10-20
        相关资源
        最近更新 更多