Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

start and stop all the services in ambari in time intervals?

avatar
Contributor

Hi everyone,

i want to start all the services in ambari in time inrevals in autmated way.

like i need all the services to start daily at 7am and i want to stop at 5pm.

so that i will start the ec2-instances at 6:30am and i will stop those by 5:30pm.

can you please help me out.

thanks in advance

1 ACCEPTED SOLUTION

avatar
Master Mentor

@pavan p

You can make use fo Ambari APIs to do the same and run the following kind of API calls using curl using Cron Job at the mentioned times.

Stop All Services of an ambari managed cluster

curl -u admin:admin  -H 'X-Requested-By:ambari' -X PUT     -d '{"RequestInfo":{"context":"_PARSE_.STOP.ALL_SERVICES","operation_level":{"level":"CLUSTER","cluster_name":"BlueprintCluster"}},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}' http://blueprint.example.com:8080/api/v1/clusters/BlueprintCluster/services?

.

Start All Services of an ambari managed cluster

curl -u admin:admin  -H 'X-Requested-By:ambari' -X PUT     -d '{"RequestInfo":{"context":"_PARSE_.START.ALL_SERVICES","operation_level":{"level":"CLUSTER","cluster_name":"BlueprintCluster"}},"Body":{"ServiceInfo":{"state":"STARTED"}}}' http://blueprint.example.com:8080/api/v1/clusters/BlueprintCluster/services?


Here following are the values that you will have to change:
BlueprintCluster: Replace it with your Cluster Name

blueprint.example.com: Replace it with your Ambari Server Hostname

.

View solution in original post

3 REPLIES 3

avatar
Master Mentor

@pavan p

You can make use fo Ambari APIs to do the same and run the following kind of API calls using curl using Cron Job at the mentioned times.

Stop All Services of an ambari managed cluster

curl -u admin:admin  -H 'X-Requested-By:ambari' -X PUT     -d '{"RequestInfo":{"context":"_PARSE_.STOP.ALL_SERVICES","operation_level":{"level":"CLUSTER","cluster_name":"BlueprintCluster"}},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}' http://blueprint.example.com:8080/api/v1/clusters/BlueprintCluster/services?

.

Start All Services of an ambari managed cluster

curl -u admin:admin  -H 'X-Requested-By:ambari' -X PUT     -d '{"RequestInfo":{"context":"_PARSE_.START.ALL_SERVICES","operation_level":{"level":"CLUSTER","cluster_name":"BlueprintCluster"}},"Body":{"ServiceInfo":{"state":"STARTED"}}}' http://blueprint.example.com:8080/api/v1/clusters/BlueprintCluster/services?


Here following are the values that you will have to change:
BlueprintCluster: Replace it with your Cluster Name

blueprint.example.com: Replace it with your Ambari Server Hostname

.

avatar
Contributor

can you please tell me how to setup cron job for the rest api

avatar
Master Mentor

@pavan p

1. Open a terminal and run the following command to open the crontab editor (it's like "vi" editor)

# crontab -e


2. Now add the following entries inside it: (here 30 17 means 5:30 PM) and similarly (30 06 means 6:30 AM)

30 17 * * * curl -u admin:admin  -H 'X-Requested-By:ambari' -X PUT     -d '{"RequestInfo":{"context":"_PARSE_.STOP.ALL_SERVICES","operation_level":{"level":"CLUSTER","cluster_name":"BlueprintCluster"}},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}' http://blueprint.example.com:8080/api/v1/clusters/BlueprintCluster/services?

30 06 * * * curl -u admin:admin  -H 'X-Requested-By:ambari' -X PUT     -d '{"RequestInfo":{"context":"_PARSE_.START.ALL_SERVICES","operation_level":{"level":"CLUSTER","cluster_name":"BlueprintCluster"}},"Body":{"ServiceInfo":{"state":"STARTED"}}}' http://blueprint.example.com:8080/api/v1/clusters/BlueprintCluster/services?

.

Reference:

https://www.drupal.org/docs/7/setting-up-cron-for-drupal/configuring-cron-jobs-using-the-cron-comman...