diff --git a/run_agent.sh b/run_agent.sh index 7c68e220e0288c5763a9da9c15d34d3ecda703b8..3fe3405d743b9a987635e3ee5fc6fb3784d598f7 100755 --- a/run_agent.sh +++ b/run_agent.sh @@ -102,8 +102,6 @@ ic_session_id=${result[1]} if [ -z ${server_url+x} ]; then echo "No Server URL set" exit 1 -else - echo "Server URL: ${server_url}" fi if [ -z ${ic_session_id+x} ]; then @@ -111,47 +109,39 @@ if [ -z ${ic_session_id+x} ]; then exit 1 fi - # Check for the existance of infaagent.ini and see if it has been registered. register=true -config_file="conf/infaagent.ini" - -if [ -e "$config_file" ]; then - - echo "Found infaagent.ini" - - agent_id=$(grep -oP '^InfaAgent.Id=\K.+' $config_file) - - # Use expansion to check for null - if [ -n "${agent_id+x}" ]; then +agent_id=$(grep -oPs '^InfaAgent.Id=\K.+' conf/infaagent.ini) - # Check the registered agent ID to see if it is running or not. - # active seems to be set to true if it has been running recently - # readyToRun means it is up and running - result=($(curl -sS -H "Content-Type: application/json" \ - -H "Accept: application/json" \ - -H "icSessionId: ${ic_session_id}" \ - "${server_url}/api/v2/agent/${agent_id}" | jq -r '.active, .readyToRun, .name')) - - if [ -z "${result[0]}" ]; then +if [ -z "${agent_id}" ]; then + echo "No agent id found, registering new agent" +else - echo "Unable to find agent_id, registering a new agent" + # If we find an agent_id, then query the Informatica API and + # check the registered agent ID to see if it is running or not. + # active seems to be set to true if it has been running recently + # readyToRun means it is up and running - elif [[ "${result[0]}" = "true" && "${result[1]}" = "true" ]]; then + echo "Checking the status of ${agent_id} using the agent API" - echo "Already exists a running agent with the id of ${agent_id}: ${result[1]}, registering a new agent" + result=($(curl -sS -H "Content-Type: application/json" \ + -H "Accept: application/json" \ + -H "icSessionId: ${ic_session_id}" \ + "${server_url}/api/v2/agent/${agent_id}" | jq -r '.active, .readyToRun, .name')) - else + if [ -z "${result[0]}" ]; then - #Not running, but exists. This should be the default condition, in which case we would just run the agent - register=false + echo "Unable to find agent_id, registering a new agent" - fi + elif [[ "${result[0]}" = "true" && "${result[1]}" = "true" ]]; then + echo "Already exists a running agent with the id of ${agent_id}, registering a new agent" else - echo "This looks to be a new agent, registering new agent" + #Not running, but exists. This should be the default condition, in which case we would just run the agent + register=false + fi fi