Scripted start / stop of HDP services
Hi,
I am trying to perform a scripted start / stop of HDP services and its components. I need to get this done service by service, because there are few components like Hive Interactive / Spark Thrift server / Kafka broker, which does not get started / stopped in proper time. Most of the times it is observed that even if HSInteractive is still starting (visible in the background operations panel on Ambari), command moves to next service to start / stop and ultimately HSI fails. Hence, I also want to ensure that previous service is completely stopped / started, before attempting to stop / start next service in the list.
To achieve, below is the script I have written (this is to stop, I have similar for start). However, when it reaches to the point for Hive or Spark or Kafka services, even though the the internal components like Hive Interactive or Spark Thrift server or Kafka broker are not started / stopped, it moves to the next service. Most of the times the start of Spark Thrift server fails via this script. However, if same API call is sent only for Spark or Hive individually it works as expected.
Shell script for reference:
USER='admin'
PASS='admin'
CLUSTER='xxxxxx'
HOST='xxxxxx:8080'
function stop(){
curl -s -u $USER:$PASS -H 'X-Requested-By: ambari' -X PUT -d '{"RequestInfo": {"context" :"Stop '"$1"' via REST"}, "Body": {"ServiceInfo": {"state": "INSTALLED"}}}' http://$HOST/api/v1/clusters/$CLUSTER/services/$1
echo -e "\nWaiting for $1 to stop...\n"
wait $1 "INSTALLED"
maintOn $1
}
function wait(){
finished=0
check=0
while [[] $finished -ne 1 ]]
do
str=$(curl -s -u $USER:$PASS http://{$HOST}/api/v1/clusters/$CLUSTER/services/$1)
if [[ $str == *"INSTALLED"* ]]
then
finished=1
echo "\n$1 Stopped...\n"
fi
check=$((check+1))
sleep 3
done
if [[ $check -eq 3 ]]
then
echo -e "\n${1} failed to stop after 3 attempts. Exiting...\n"
exit $?
fi
}
function maintOn(){
curl -u $USER:$PASS -i -H 'X-Requested-By: ambari' -X PUT -d '{"RequestInfo":{"context":"Turn ON Maintenance Mode for $1 via Rest"},"Body":{"ServiceInfo":{"maintenance_state":"ON"}}}' http://$HOST/api/v1/clusters/$CLUSTER/services/$1
}
stop AMBARI_INFRA_SOLR
stop AMBARI_METRICS
stop HDFS
stop HIVE
stop KAFKA
stop MAPREDUCE2
stop SPARK2
stop YARN
stop ZOOKEEPER
Any help / guidance would be great.
Thanks
Snm1523

