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.

How can I stop the entire HDP stack via the CLI?

Solved Go to solution

How can I stop the entire HDP stack via the CLI?

Contributor

How can I stop the entire HDP stack of services from the CLI? I seem to recall that there was a command to accomplish this but I can not find it. It would seem like this facility would be associated with the ambari-agent service but I did not see any such method/action on the usage for this script/service.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: How can I stop the entire HDP stack via the CLI?

Contributor

You can use a script like this to perform the shutdown of a cluster. The script below will first determine the cluster's name and then use it in subsequent calls to the API.

USER=admin
PASSWORD=admin
AMBARI_HOST=localhost

#detect name of cluster
CLUSTER=$(curl -s -u $USER:$PASSWORD -i -H 'X-Requested-By: ambari' \
   http://$AMBARI_HOST:8080/api/v1/clusters | \
   sed -n 's/.*"cluster_name" : "\([^\"]*\)".*/\1/p')

#stop all services
curl -u $USER:$PASSWORD -i -H 'X-Requested-By: ambari' -X PUT \
   -d '{"RequestInfo":{"context":"_PARSE_.STOP.ALL_SERVICES","operation_level":{"level":"CLUSTER","cluster_name":"Sandbox"}},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}' \
   http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER/services

#start all services
curl -u $USER:$PASSWORD -i -H 'X-Requested-By: ambari' -X PUT \
   -d '{"RequestInfo":{"context":"_PARSE_.START.ALL_SERVICES","operation_level":{"level":"CLUSTER","cluster_name":"Sandbox"}},"Body":{"ServiceInfo":{"state":"STARTED"}}}' \
   http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER/service

When you run the above you'll see a response from the API like so (NOTE: here my cluster is called "dev09_ost_hivetest_h"):

HTTP/1.1 202 Accepted
User: admin
Set-Cookie: AMBARISESSIONID=1t9w52ud2xali10ofo3r9uw2t4;Path=/;HttpOnly
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Type: text/plain
Vary: Accept-Encoding, User-Agent
Content-Length: 150
Server: Jetty(8.1.17.v20150415)

{
  "href" : "http://localhost:8080/api/v1/clusters/dev09_ost_hivetest_h/requests/42",
  "Requests" : {
    "id" : 42,
    "status" : "Accepted"
  }

You can take the request ID ("id": 42) and monitor it to see if it's completed.

$ curl -s -u admin:admin -i -H 'X-Requested-By: ambari' http://localhost:8080/api/v1/clusters/dev09_ost_hivetest_h/requests/42

HTTP/1.1 200 OK
User: admin
Set-Cookie: AMBARISESSIONID=ypsi94kpge383tn0n1aosf9p;Path=/;HttpOnly
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Type: text/plain
Vary: Accept-Encoding, User-Agent
Content-Length: 5593
Server: Jetty(8.1.17.v20150415)

{
  "href" : "http://localhost:8080/api/v1/clusters/dev09_ost_hivetest_h/requests/42",
  "Requests" : {
    "aborted_task_count" : 0,
    "cluster_name" : "dev09_ost_hivetest_h",
    "completed_task_count" : 16,
    "create_time" : 1455901657726,
    "end_time" : 1455901773056,
    "exclusive" : false,
    "failed_task_count" : 0,
    "id" : 42,
    "inputs" : null,
    "operation_level" : null,
    "progress_percent" : 100.0,
    "queued_task_count" : 0,
    "request_context" : "_PARSE_.STOP.ALL_SERVICES",
    "request_schedule" : null,
    "request_status" : "COMPLETED",
    "resource_filters" : [ ],
    "start_time" : 1455901657749,
    "task_count" : 16,
    "timed_out_task_count" : 0,
    "type" : "INTERNAL_REQUEST"
  },
...
...

When it says COMPLETED, the shutdown is done.

6 REPLIES 6

Re: How can I stop the entire HDP stack via the CLI?

@Sam Mingolelli I am not sure if there was ever any single CLI command to stop entire HDP stack. But you can use Ambari APIs to start or stop all services. Refer below for the same.

https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=41812517

Re: How can I stop the entire HDP stack via the CLI?

Contributor

curl -u <USERNAME>:<PASSWORD> -H 'X-Requested-By:ambari' -X PUT -d '{"RequestInfo":{"context":"Stop All Services","operation_level":{"level":"CLUSTER","cluster_name":"cl1"}},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}' http://<AMBARI-SERVER>:8080/api/v1/clusters/cl1/services

Re: How can I stop the entire HDP stack via the CLI?

Re: How can I stop the entire HDP stack via the CLI?

Mentor

@Sam Mingolelli please accept the best answer or provide your own solution.

Highlighted

Re: How can I stop the entire HDP stack via the CLI?

Contributor

You can use a script like this to perform the shutdown of a cluster. The script below will first determine the cluster's name and then use it in subsequent calls to the API.

USER=admin
PASSWORD=admin
AMBARI_HOST=localhost

#detect name of cluster
CLUSTER=$(curl -s -u $USER:$PASSWORD -i -H 'X-Requested-By: ambari' \
   http://$AMBARI_HOST:8080/api/v1/clusters | \
   sed -n 's/.*"cluster_name" : "\([^\"]*\)".*/\1/p')

#stop all services
curl -u $USER:$PASSWORD -i -H 'X-Requested-By: ambari' -X PUT \
   -d '{"RequestInfo":{"context":"_PARSE_.STOP.ALL_SERVICES","operation_level":{"level":"CLUSTER","cluster_name":"Sandbox"}},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}' \
   http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER/services

#start all services
curl -u $USER:$PASSWORD -i -H 'X-Requested-By: ambari' -X PUT \
   -d '{"RequestInfo":{"context":"_PARSE_.START.ALL_SERVICES","operation_level":{"level":"CLUSTER","cluster_name":"Sandbox"}},"Body":{"ServiceInfo":{"state":"STARTED"}}}' \
   http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER/service

When you run the above you'll see a response from the API like so (NOTE: here my cluster is called "dev09_ost_hivetest_h"):

HTTP/1.1 202 Accepted
User: admin
Set-Cookie: AMBARISESSIONID=1t9w52ud2xali10ofo3r9uw2t4;Path=/;HttpOnly
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Type: text/plain
Vary: Accept-Encoding, User-Agent
Content-Length: 150
Server: Jetty(8.1.17.v20150415)

{
  "href" : "http://localhost:8080/api/v1/clusters/dev09_ost_hivetest_h/requests/42",
  "Requests" : {
    "id" : 42,
    "status" : "Accepted"
  }

You can take the request ID ("id": 42) and monitor it to see if it's completed.

$ curl -s -u admin:admin -i -H 'X-Requested-By: ambari' http://localhost:8080/api/v1/clusters/dev09_ost_hivetest_h/requests/42

HTTP/1.1 200 OK
User: admin
Set-Cookie: AMBARISESSIONID=ypsi94kpge383tn0n1aosf9p;Path=/;HttpOnly
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Type: text/plain
Vary: Accept-Encoding, User-Agent
Content-Length: 5593
Server: Jetty(8.1.17.v20150415)

{
  "href" : "http://localhost:8080/api/v1/clusters/dev09_ost_hivetest_h/requests/42",
  "Requests" : {
    "aborted_task_count" : 0,
    "cluster_name" : "dev09_ost_hivetest_h",
    "completed_task_count" : 16,
    "create_time" : 1455901657726,
    "end_time" : 1455901773056,
    "exclusive" : false,
    "failed_task_count" : 0,
    "id" : 42,
    "inputs" : null,
    "operation_level" : null,
    "progress_percent" : 100.0,
    "queued_task_count" : 0,
    "request_context" : "_PARSE_.STOP.ALL_SERVICES",
    "request_schedule" : null,
    "request_status" : "COMPLETED",
    "resource_filters" : [ ],
    "start_time" : 1455901657749,
    "task_count" : 16,
    "timed_out_task_count" : 0,
    "type" : "INTERNAL_REQUEST"
  },
...
...

When it says COMPLETED, the shutdown is done.

Re: How can I stop the entire HDP stack via the CLI?