简体   繁体   中英

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?

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

如果您在运行 Solr 的同一台机器上,那么这是我的最爱:

$> solr status

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM