Support Questions
Find answers, ask questions, and share your expertise

script for start and stop Hadoop services in sequence?

Highlighted

script for start and stop Hadoop services in sequence?

Hi,

We hosted multiple Hadoop clusters and VM on Azure, and as per the requirement needs to create a script to start and stop the Hadoop clusters and other VM in a sequence as mentioned below:

1. stop all the hadoop services--> stop cloudbreak -> stop all VM

2. Start all VM --> start cloudbreak --> start all hadoop services (for hadoop don't know the sequence of services)

Any suggestion on how to implement this? @Jay Kumar SenSharma

5 REPLIES 5
Highlighted

Re: script for start and stop Hadoop services in sequence?

@Nitin Bandil

To stop all the services, You can use the following ambari api :

curl -i -u admin:admin -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://localhost:8080/api/v1/clusters/Sandbox/services 

To start all the services, You can use the following ambari api :

curl -i -u admin:admin -H "X-Requested-By: ambari"  -X PUT  -d '{"RequestInfo":{"context":"_PARSE_.STOP.ALL_SERVICES","operation_level":{"level":"CLUSTER","cluster_name":"Sandbox"}},"Body":{"ServiceInfo":{"state":"STARTED"}}}' http://localhost:8080/api/v1/clusters/Sandbox/services

Hope this helps.

Highlighted

Re: script for start and stop Hadoop services in sequence?

@Nitin Bandil

Did the above mentioned api's helped in addressing your query? If yes, Could you please login and mark this answer as "Accept" to close this thread.

Highlighted

Re: script for start and stop Hadoop services in sequence?

Hi,

Thanks for the help, but how it will work for multiple clusters and nodes. Do I need to hardcode this script for each and individual node or Is there any other way so it fetches the info like cluster_name, href? @Sandeep Nemuri

Highlighted

Re: script for start and stop Hadoop services in sequence?

@Nitin Bandil

We'd need to pass the cluster_name and execute the api's separately for each cluster.

Highlighted

Re: script for start and stop Hadoop services in sequence?

Hi @Sandeep Nemuri,

Below is the script I am working on and its working fine when I am running the same on ambari host but it's started giving an error when the same running on its nodes because that time localhost gets changed.

Can you please suggest me what to use to get the ambari host value when I will erun the same script on different nodes?

#!/bin/bash

AMBARI_HOST=localhost

echo "AMBARI_HOST: "$AMBARI_HOST

HOST_NAME=$(hostname --fqdn)

echo "HOST_NAME: "HOST_NAME

AMBARI_PASSWORD=xxxxxxxxxxxx

#detect name of cluster #

CLUSTER_OUTPUT=$(curl -u admin:$AMBARI_PASSWORD -i -H 'X-Requested-By: ambari' http://$AMBARI_HOST:8080/api/v1/clusters)

export CLUSTER=$(echo $CLUSTER_OUTPUT | sed -n 's/.*"cluster_name" : "\([^\"]*\)".*/\1/p')

echo $CLUSTER

curl -iv -u admin:$AMBARI_PASSWORD -H "X-Requested-By: ambari" -X PUT -d '{"RequestInfo":{"context":"Stopping All Host Components","operation_level": {"level":"HOST","cluster_name":"autoshutdown", "host_names":"$HOST_NAME"},"query":"HostRoles/component_name/*"}, "Body": {"HostRoles": {"state":"INSTALLED"}}}' http://$AMBARI_HOST:8080/api/v1/clusters/autoshutdown/hosts/$HOST_NAME/host_components