Wednesday, February 2, 2022

[SOLVED] Homebrew: How to check if a homebrew service is switched on or not

Issue

I am using elasticsearch instance as a nosql database. This was installed with brew on mac os.

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



Answered By - Mani
Answer Checked By - Senaida (WPSolving Volunteer)