This is an automated email from the ASF dual-hosted git repository. wenweihuang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/inlong.git
The following commit(s) were added to refs/heads/master by this push: new c99a0eb0c7 [INLONG-11518][Agent] Support multiple processes (#11519) c99a0eb0c7 is described below commit c99a0eb0c7acda01edcbf37541f4a1263cc1bf69 Author: justinwwhuang <hww_jus...@163.com> AuthorDate: Thu Nov 21 17:18:17 2024 +0800 [INLONG-11518][Agent] Support multiple processes (#11519) --- inlong-agent/agent-installer/bin/installer.sh | 28 +++++++++++++++++------ inlong-agent/bin/agent.sh | 33 +++++++++++++++++++-------- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/inlong-agent/agent-installer/bin/installer.sh b/inlong-agent/agent-installer/bin/installer.sh index 09a412348d..729f0f2de7 100755 --- a/inlong-agent/agent-installer/bin/installer.sh +++ b/inlong-agent/agent-installer/bin/installer.sh @@ -31,13 +31,27 @@ function help() { echo " help: get help from agent installer" } +function getPid() { + local process_name="installer.Main" + local user=$(whoami) + local pid=$(ps -u $user -f | grep 'java' | grep "$process_name" | grep -v grep | awk '{print $2}') + + if [ -z "$pid" ]; then + echo "No matching process found." + return 1 + fi + + echo "$pid" + return 0 +} + function running() { - process=$("$JPS" -l| grep "installer.Main" | grep -v grep) - if [ "${process}" = "" ]; then - return 1; - else - return 0; - fi + pid=$(getPid) + if [ $? -eq 0 ]; then + return 0 + else + return 1 + fi } # start installer @@ -56,7 +70,7 @@ function stop_installer() { exit 1 fi count=0 - pid=$("$JPS" -l| grep "installer.Main"| grep -v grep | awk '{print $1}') + pid=$(getPid) while running; do (( count++ )) diff --git a/inlong-agent/bin/agent.sh b/inlong-agent/bin/agent.sh index 9d5bc86686..5db202394f 100755 --- a/inlong-agent/bin/agent.sh +++ b/inlong-agent/bin/agent.sh @@ -37,13 +37,28 @@ function help() { echo " help: get help from inlong agent" } + +function getPid() { + local process_name="inlong-agent" + local user=$(whoami) + local pid=$(ps -u $user -f | grep 'java' | grep "$process_name" | grep -v grep | awk '{print $2}') + + if [ -z "$pid" ]; then + echo "No matching process found." + return 1 + fi + + echo "$pid" + return 0 +} + function running() { - process=$("$JPS" | grep "AgentMain" | grep -v grep) - if [ "${process}" = "" ]; then - return 1; - else - return 0; - fi + pid=$(getPid) + if [ $? -eq 0 ]; then + return 0 + else + return 1 + fi } # start agent @@ -53,9 +68,9 @@ function start_agent() { exit 1 fi if [ "$ENABLE_OBSERVABILITY" = "true" ]; then - nohup ${JAVA} ${AGENT_ARGS} -javaagent:${OTEL_AGENT} org.apache.inlong.agent.core.AgentMain > /dev/null 2>&1 & + nohup ${JAVA} ${AGENT_ARGS} ${arg_uniq} -javaagent:${OTEL_AGENT} org.apache.inlong.agent.core.AgentMain > /dev/null 2>&1 & else - nohup ${JAVA} ${AGENT_ARGS} org.apache.inlong.agent.core.AgentMain > /dev/null 2>&1 & + nohup ${JAVA} ${AGENT_ARGS} ${arg_uniq} org.apache.inlong.agent.core.AgentMain > /dev/null 2>&1 & fi } @@ -66,7 +81,7 @@ function stop_agent() { exit 1 fi count=0 - pid=$("$JPS" | grep "AgentMain" | grep -v grep | awk '{print $1}') + pid=$(getPid) while running; do (( count++ ))