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

creat script that stop hive on My cluster

Expert Contributor

I need to create a script shell that stops the Hive Metastore and Hive Server2 from any node of cluster and I need to know where the hive is hosted in My cluster in order to run this command:

ssh nodename:ps aux | awk '{print $1,$2}' | grep hive | awk '{print $2}' | xargs kill >/dev/null 2>&1

how can I know where nodes hive is hosted?

1 ACCEPTED SOLUTION

Accepted Solutions

Super Mentor

@yassine sihi

If you have Ambari managed cluster then you can find that information just by a simple API call:

1. To findout Hive metastore host:

# curl -u admin:admin -H "X-Requested-By: ambari" -X GET http://amb25101.example.com:8080/api/v1/clusters/plain_ambari/services/HIVE/components/HIVE_METASTOR... | grep 'host_name' | awk '{print $NF}' 

2. To findout Hive Server2 host.

# curl -u admin:admin -H "X-Requested-By: ambari" -X GET http://amb25101.example.com:8080/api/v1/clusters/plain_ambari/services/HIVE/components/HIVE_SERVER | grep 'host_name' | awk '{print $NF}' 

.

You will need to replace "amb25101.example.com" with Ambari Server Hostname. Also the "plain_ambari" with your Ambari cluster name.

View solution in original post

9 REPLIES 9

Super Mentor

@yassine sihi

If you have Ambari managed cluster then you can find that information just by a simple API call:

1. To findout Hive metastore host:

# curl -u admin:admin -H "X-Requested-By: ambari" -X GET http://amb25101.example.com:8080/api/v1/clusters/plain_ambari/services/HIVE/components/HIVE_METASTOR... | grep 'host_name' | awk '{print $NF}' 

2. To findout Hive Server2 host.

# curl -u admin:admin -H "X-Requested-By: ambari" -X GET http://amb25101.example.com:8080/api/v1/clusters/plain_ambari/services/HIVE/components/HIVE_SERVER | grep 'host_name' | awk '{print $NF}' 

.

You will need to replace "amb25101.example.com" with Ambari Server Hostname. Also the "plain_ambari" with your Ambari cluster name.

View solution in original post

Expert Contributor

@Jay Kumar SenSharma

is there some alternative to stop the whole service "hive service" on one command??

Super Mentor

@yassine sihi

To stop whole "Hive Service"

# curl -u admin:admin -H "X-Requested-By: ambari" -X PUT -d '{"RequestInfo":{"context":"_PARSE_.START.HIVE","operation_level":{"level":"SERVICE","cluster_name":"plain_ambari","service_name":"HIVE"}},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}' http://amb25101.example.com:8080/api/v1/clusters/plain_ambari/services/HIVE

.

To start whole "Hive Service"

# curl -u admin:admin -H "X-Requested-By: ambari" -X PUT -d '{"RequestInfo":{"context":"_PARSE_.START.HIVE","operation_level":{"level":"SERVICE","cluster_name":"plain_ambari","service_name":"HIVE"}},"Body":{"ServiceInfo":{"state":"STARTED"}}}' http://amb25101.example.com:8080/api/v1/clusters/plain_ambari/services/HIVE

.

Super Mentor

@yassine sihi

Similarly you can use the following API calls to stop the HIveServer2 & Metastore:

To stop HiveServer2 on host "amb25103.example.com"

# curl -u admin:admin -H "X-Requested-By: ambari" -X PUT  -d '{"RequestInfo":{"context":"Stop HiveServer2","operation_level":{"level":"HOST_COMPONENT","cluster_name":"plain_ambari","host_name":"amb25103.example.com","service_name":"HIVE"}},"Body":{"HostRoles":{"state":"INSTALLED"}}}' http://amb25101.example.com:8080/api/v1/clusters/plain_ambari/hosts/amb25103.example.com/host_compon...?



To stop HiveMetastore on host "amb25103.example.com"

# curl -u admin:admin -H "X-Requested-By: ambari" -X PUT  -d '{"RequestInfo":{"context":"Stop Hive Metastore","operation_level":{"level":"HOST_COMPONENT","cluster_name":"plain_ambari","host_name":"amb25103.example.com","service_name":"HIVE"}},"Body":{"HostRoles":{"state":"INSTALLED"}}}' http://amb25101.example.com:8080/api/v1/clusters/plain_ambari/hosts/amb25103.example.com/host_compon...?

.

Expert Contributor

@Jay Kumar SenSharma

do I need to run the both command to stop hive, isn't there one command that can do this??

Super Mentor

@Yassine

If this answers your query then please mark this thread as answered by clicking on the "Accepted" button that way other HCC users can quickly browser the answered queries.

Expert Contributor

@Jay Kumar SenSharma

Do I need to run the both command to stop hive service, isn't there one line command that can do this??

Super Mentor

@yassine sihi

One command is to To stop HiveServer2 on host "amb25103.example.com"

And the other command is to To stop HiveMetastore on host "amb25103.example.com"

.

If you want to stop the Whole Hive Service then please refer to my previous command in same thread:

To stop whole "Hive Service"

# curl -u admin:admin -H "X-Requested-By: ambari" -X PUT -d '{"RequestInfo":{"context":"_PARSE_.START.HIVE","operation_level":{"level":"SERVICE","cluster_name":"plain_ambari","service_name":"HIVE"}},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}' http://amb25101.example.com:8080/api/v1/clusters/plain_ambari/services/HIVE

.

To start whole "Hive Service"

# curl -u admin:admin -H "X-Requested-By: ambari" -X PUT -d '{"RequestInfo":{"context":"_PARSE_.START.HIVE","operation_level":{"level":"SERVICE","cluster_name":"plain_ambari","service_name":"HIVE"}},"Body":{"ServiceInfo":{"state":"STARTED"}}}' http://amb25101.example.com:8080/api/v1/clusters/plain_ambari/services/HIVE
.


Expert Contributor