Search code examples
ibm-cloudanalytics-engine

How to determine which services to restart after a configuration change?


I need to make some changes to my cluster using the Ambari API. After making the changes, I'm using the following code to restart all of the service:

echo "stop and Start Services"

curl -k -v --user $AMBARI_USER:$AMBARI_PASSWORD -H "X-Requested-By: ambari" -i -X PUT -d '{"RequestInfo": {"context": "Stop All Services via REST"}, "ServiceInfo": {"state":"INSTALLED"}}' https://$AMBARI_HOST:$AMBARI_PORT/api/v1/clusters/$CLUSTER_NAME/services

sleep 200

curl -k -v --user $AMBARI_USER:$AMBARI_PASSWORD -H "X-Requested-By: ambari" -i -X PUT -d '{"RequestInfo": {"context": "Start All Services via REST"}, "ServiceInfo":{"state":"STARTED"}}' https://$AMBARI_HOST:$AMBARI_PORT/api/v1/clusters/$CLUSTER_NAME/services

sleep 700

This seems to be very heavy-weight. Is there a way to only restart the services that need restarting?


Solution

  • One option is to use this to restart only the services that need restarting due to reconfiguration:

    curl -v --user $AMBARI_USER:$AMBARI_PASSWORD -H "X-Requested-By: ambari" -i -X POST -d '{ "RequestInfo": {"command": "RESTART","context": "Restart all required services","operation_level": "host_component"}, "Requests/resource_filters": [{"hosts_predicate": "HostRoles/stale_configs=true" }] }' https://$AMBARI_HOST:$AMBARI_PORT/api/v1/clusters/$CLUSTER_NAME/requests

    To check on the status of the above command:

    curl -v --user $AMBARI_USER:$AMBARI_PASSWORD -H "X-Requested-By: ambari" -X GET https://$AMBARI_HOST:$AMBARI_PORT/api/v1/clusters/$CLUSTER_NAME/requests/132