Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to confirm Solr is running from the command line?

We have a few servers that are going to be rebooted soon and I may have to restart Apache Solr manually.

How can I verify (from the command line) that Solr is running?

like image 886
doub1ejack Avatar asked Mar 04 '15 04:03

doub1ejack


2 Answers

The proper way is to use Solr's STATUS command. You could parse its XML response, but as long as it returns something to you with an HTTP status of 200, it should be safe to assume it's running. You can perform an HTTP HEAD request using curl with:

curl -s -o /dev/null -I -w '%{http_code}' http://example.com:8983/solr/admin/cores?action=STATUS
  • NOTE: Also, you can add a -m <seconds> to the command to only wait so many seconds for a response.

This will make a request to the Solr admin interface, and print out 200 on success which can be used from a bash script such as:

RESULT=$(curl -s -o /dev/null -I -w '%{http_code}' http://example.com:8983/solr/admin/cores?action=STATUS)
if [ "$RESULT" -eq '200' ]; then
    # Solr is running...
else
    # Solr is not running...
fi
like image 126
Uyghur Lives Matter Avatar answered Sep 20 '22 22:09

Uyghur Lives Matter


If you are on the same machine where Solr is running then this is my favourite:

$> solr status
like image 33
Nicola Mingotti Avatar answered Sep 21 '22 22:09

Nicola Mingotti