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

Viewed 5171

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
2 Answers

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

Just run:

brew services

Sample Output

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 

You can also run the following command to get the process id (pid) of the homebrew services:

launchctl list | grep homebrew

460 0   homebrew.mxcl.influxdb
484 0   homebrew.mxcl.grafana
469 0   homebrew.mxcl.redis
Related