Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Restart Solr from command line

Solved Go to solution

Restart Solr from command line

Explorer

I am wondering if there is a way to restart Solr from the command line? I would like to script a restart of solr every night so that I dont have to do it manually.

Thank You

Jamie

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Restart Solr from command line

Rising Star

If you are using Cloudera Manager, you can use the API present to do that.

The end point you will like to use will be : /cm/service/roleCommands/restart

I would not recommend to do restart outside of the CM cause the management will be difficult.

 

 

Doc Link : https://cloudera.github.io/cm_api/apidocs/v12/

4 REPLIES 4

Re: Restart Solr from command line

Rising Star

If you are using Cloudera Manager, you can use the API present to do that.

The end point you will like to use will be : /cm/service/roleCommands/restart

I would not recommend to do restart outside of the CM cause the management will be difficult.

 

 

Doc Link : https://cloudera.github.io/cm_api/apidocs/v12/

Re: Restart Solr from command line

Explorer

Thank you that gives me exactly what I needed. Why would you say that management would be difficult?

 

Jamie

Re: Restart Solr from command line

Rising Star
If a node dies, it will be difficult to track which one died and which ones are running.
If you have installed it completely outside of CM and are using an external Management tool, then you might have to deal with how other services interact with each other .

Hope this helps.

Re: Restart Solr from command line

Explorer

#!/usr/bin/env python
import ssl,sys,time
from cm_api.api_client import ApiResource
from cm_api.endpoints.types import ApiClusterTemplate
from cm_api.endpoints.cms import ClouderaManager
from cm_api.endpoints import clusters, events, hosts, external_accounts, tools
from cm_api.endpoints import types, users, timeseries, roles, services

ssl._create_default_https_context = ssl._create_unverified_context
try:
  cm = ApiResource("CM_SERVER","7183","admin","CM_PASS","true","15")
  cluster = cm.get_cluster("CLUSTER_NAME")
except:
  print "Failed log into cluster %s" % ("CLUSTER_NAME")
  sys.exit(0)

servers = [
"server1.company.com",
"server2.company.com",
"server3.company.com"]

s = cluster.get_service("solr")
ra = []
for r in s.get_roles_by_type("SOLR_SERVER"):
  hostname = cm.get_host(r.hostRef.hostId).hostname
  if hostname in servers:
    ra.append([hostname,r])
ra.sort()
print "\nWill restart %s SOLR instances" % len(ra)
for hostname,r in ra:
  print "\nRestarting SOLR on %s" % (hostname)
  s.restart_roles(r.name)
  r = s.get_role(r.name)
  wait = time.time() + 180 # three minutes
  while r.roleState != "STARTED":
    print "Role State = %s" % (r.roleState)
    print "Waiting for role state to be STARTED"
    print time.strftime("%H:%M:%S")
    if time.time() > wait:
      print "SOLR failed to restart on %s" % (hostname)
      sys.exit(1)
    time.sleep(10)
    r = s.get_role(r.name)
  print "SOLR restarted on %s" % (hostname)

print "\nAll SOLR roles restarted"
sys.exit(0)