bashshellelasticsearchcurlhomebrew

How to check if a homebrew service is switched on or not


I am using an Elasticsearch instance as a NoSQL database. This was installed with brew on macOS.

This is how I start Elasticsearch:

brew services start elasticsearch

I was wondering if there is a brew command (or other) where I can know if an Elasticsearch instance is on or not.

Ultimately I want to run a bash script that does the following:

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

Solution

  • brew services list gives the status of the services. so something like brew services list | grep elastiscearch | awk '{ print $2}' should return the status of the elastic search service, whether started or stopped