2

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

我就是这样开始elasticsearch的。

brew services start elasticsearch

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

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

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

2 回答 2

4

brew services list给出服务状态。所以应该返回弹性搜索服务的状态,无论是启动还是停止brew services list | grep elastiscearch | awk '{ print $2}'

于 2020-12-21T15:43:25.307 回答
0

赶紧跑:

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 

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

launchctl list | grep homebrew

460 0   homebrew.mxcl.influxdb
484 0   homebrew.mxcl.grafana
469 0   homebrew.mxcl.redis
于 2020-12-21T15:46:43.193 回答