From f9d7bb44663f30aabf40349ffd76de71e30d543e Mon Sep 17 00:00:00 2001 From: Eric Schoville <eric@schoville.com> Date: Fri, 17 Jan 2020 11:31:28 -0600 Subject: [PATCH] Update run_agent.sh --- run_agent.sh | 50 ++++++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/run_agent.sh b/run_agent.sh index 7c68e22..3fe3405 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 -- GitLab