Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]
Created 04-25-2016 05:35 PM
Is there any single curl command to restart all the services with stale configurations using Ambari API ?
Created 04-25-2016 06:17 PM
Unfortunately this is not a part of the release branch. The patch is committed to trunk and scheduled for 2.4.0.
Created 04-25-2016 06:17 PM
Unfortunately this is not a part of the release branch. The patch is committed to trunk and scheduled for 2.4.0.
Created 04-25-2016 07:48 PM
Thanks @swagle
Created 04-25-2016 07:54 PM
Okay till we get single command, I have created below script which can be useful for others who has same question 🙂
[root@sandbox test12334]# cat ambari.props CLUSTER_NAME=Sandbox AMBARI_ADMIN_USER=admin AMBARI_ADMIN_PASSWORD=admin AMBARI_HOST=sandbox.hortonworks.com
[root@sandbox test12334]# cat restart_services.sh
#!/bin/bash
#Author - Kuldeep Kulkarni (http://crazyadmins.com)
#############
LOC=`pwd`
PROP=ambari.props
source $LOC/$PROP
#############
start_stale_services()
{
echo "curl -u $AMBARI_ADMIN_USER:$AMBARI_ADMIN_PASSWORD http://$AMBARI_HOST:8080/api/v1/clusters/Sandbox/host_components?HostRoles/stale_configs=true&fields=HostRoles/service_name,HostRoles/host_name&minimal_response=false"> /tmp/curl_ambari.sh
sh /tmp/curl_ambari.sh 1 > /tmp/stale_services_json 2>/dev/null
sleep 1
grep host_components /tmp/stale_services_json|grep -v stale|rev|cut -d'"' -f2|rev > /tmp/list_of_components
for URL in `cat /tmp/list_of_components`
do
curl -u $AMBARI_ADMIN_USER:$AMBARI_ADMIN_PASSWORD -i -H 'X-Requested-By: ambari' -X PUT -d '{"HostRoles": {"state": "INSTALLED"}}' "$URL"
sleep 0.5
curl -u $AMBARI_ADMIN_USER:$AMBARI_ADMIN_PASSWORD -i -H 'X-Requested-By: ambari' -X PUT -d '{"HostRoles": {"state": "STARTED"}}' "$URL"
done
}
start_stale_servicesNote - to run this script, you should have ambari.props and script at the same location.
I tried below curl call to stop all/start all but it did not clear the stale service restart alerts hence I had to come up with above workaround.
curl -u admin:$PASSWORD -i -H 'X-Requested-By: ambari' -X PUT -d '{"RequestInfo": {"context" :"Stop HDFS via REST"}, "Body": {"ServiceInfo": {"state": "INSTALLED"}}}' http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME/servicescurl -u admin:$PASSWORD -i -H 'X-Requested-By: ambari' -X PUT -d '{"RequestInfo": {"context" :"Stop HDFS via REST"}, "Body": {"ServiceInfo": {"state": "STARTED"}}}' http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME/services
Created 04-25-2016 07:55 PM
@swagle ^^
Created 04-25-2016 07:58 PM
The Start All/Stop All works just the same although there is a slight delay in updating the state which would mean stae alert not cleared immediately. I believe we send config tags from the agent only after a certain number if heartbeats.
However, what you have in the scrip is exactly what the UI does, so that should work just fine. (+1)
Created 04-25-2016 08:11 PM
@swagle Thank you. I will check with start all/stop all again.