Activity Monitoring and Automatic Startup of Agent

By using sample scripts shown below, you can configure the automatic Agent startup process to resolve the unexpected Agent termination.

By registering the sample script in the scheduler and executing it regularly, you can monitor the Agent activity and enable the automatic Agent startup.

Select a sample script depending on your Agent startup method.

Note

To improve quality, the contents of the sample script are subject to change without prior notice.

In addition, note that the sample scripts are not supported under any support service.

@echo off
setlocal enabledelayedexpansion

REM --------------------------------------- 
REM  Settings 
REM --------------------------------------- 
REM Agent Installation Directory 
set "AGENT_PATH=C:\webconnect-agent\bin"
REM Service Name 
set SERVICE_NAME=webconnect-agent
REM Status Check Retry Max. Count 
set /a MAX_RETRY=10 

REM --------------------------------------- 
REM  Initial Processing 
REM --------------------------------------- 
set "CURRENT_DIR=%~dp0"
cd /d "%AGENT_PATH%"

REM check directory 
if %ERRORLEVEL% neq 0 (
  echo Cannot cd to !AGENT_PATH! 
  goto :ERROR_END
)

set DO_NET_STOP=0 

REM Retry Counter 
set /a COUNTER=1 

REM --------------------------------------- 
REM  Status Check of Sending-side Agent 
REM --------------------------------------- 
:CHECK_SENDING-AGENT_STATUS
echo CHECK_SENDING-AGENT_STATUS
FOR /f "DELIMS=" %%i IN ('agentctl.bat -s status') DO SET SENDING-AGENT_STATUS=%%i
echo RESULT: %SENDING-AGENT_STATUS% 

echo %SENDING-AGENT_STATUS% | findstr "001" 1>nul 
if %ERRORLEVEL%==0 (
  echo Waiting for starting the sending-side Agent.
  call :SLEEP
  goto :CHECK_SENDING-AGENT_STATUS
)

echo %SENDING-AGENT_STATUS% | findstr "000" 1>nul 
if %ERRORLEVEL%==0 (
  echo Starting the sending-side Agent.
  set DO_NET_STOP=1 
  goto :START_SERVICE
)

echo %SENDING-AGENT_STATUS% | findstr "100" 1>nul 
if %ERRORLEVEL%==0 (
  echo Starting the sending-side Agent.
  set DO_NET_STOP=1 
  goto :START_SERVICE
)

echo %SENDING-AGENT_STATUS% | findstr "255" 1>nul 
if %ERRORLEVEL%==0 (
  echo Starting the sending-side Agent.
  set DO_NET_STOP=1 
  goto :START_SERVICE
)

REM --------------------------------------- 
REM  Status Check of Receiving-side Agent 
REM --------------------------------------- 
:CHECK_RECEIVING-AGENT_STATUS
echo CHECK_RECEIVING-AGENT_STATUS
FOR /f "DELIMS=" %%i IN ('agentctl.bat -r status') DO SET RECEIVING-AGENT_STATUS=%%i 
echo RESULT: %RECEIVING-AGENT_STATUS% 

echo %RECEIVING-AGENT_STATUS% | findstr "001" 1>nul 
if %ERRORLEVEL%==0 (
  echo Waiting for starting the receiving-side Agent.
  call :SLEEP
  goto :CHECK_RECEIVING-AGENT_STATUS
)

echo %RECEIVING-AGENT_STATUS% | findstr "000" 1>nul 
if %ERRORLEVEL%==0 (
  echo Starting the receiving-side Agent.
  set DO_NET_STOP=1 
  goto :START_SERVICE
)

echo %RECEIVING-AGENT_STATUS% | findstr "100" 1>nul 
if %ERRORLEVEL%==0 (
  echo Starting the receiving-side Agent.
  set DO_NET_STOP=1 
  goto :START_SERVICE
)

echo %RECEIVING-AGENT_STATUS% | findstr "255" 1>nul 
if %ERRORLEVEL%==0 (
  echo Starting the receiving-side Agent.
  set DO_NET_STOP=1 
  goto :START_SERVICE
)

goto :END

:START_SERVICE

if !COUNTER! GTR !MAX_RETRY! (
  goto :ERROR_END
)

set /a COUNTER+=1 
sc query %SERVICE_NAME% | findstr STATE | findstr STOPPED > nul 
if !ERRORLEVEL! neq 0 (
  if %DO_NET_STOP%==1 (
    call net stop "!SERVICE_NAME!"
    call :SLEEP
    call :WAIT_TO_STOP_BOTH_AGENTS
    goto :START_SERVICE
  )
)

call net start "%SERVICE_NAME%"
call :SLEEP
goto :CHECK_SENDING-AGENT_STATUS


:SLEEP
ping -n 10 localhost > nul 
exit /B 0 

:WAIT_TO_STOP_BOTH_AGENTS
FOR /f "DELIMS=" %%i IN ('agentctl.bat -r status') DO SET RECEIVING-AGENT_STATUS=%%i 
echo %RECEIVING-AGENT_STATUS% | findstr "100" 1>nul 
if %ERRORLEVEL% neq 0 (
  call :SLEEP
  goto :WAIT_TO_STOP_BOTH_AGENTS
)
exit /B 0 

:END
cd /d %CURRENT_DIR% 
exit /B

:ERROR_END
echo Failed to start Agent.
exit /b -1 

@echo off
setlocal enabledelayedexpansion

REM --------------------------------------- 
REM  Settings 
REM --------------------------------------- 
REM Agent Installation Directory 
set "AGENT_PATH=C:\webconnect-agent\bin"
REM Status Check Retry Max. Count 
set /a MAX_RETRY=10 

REM --------------------------------------- 
REM  Initial Processing 
REM --------------------------------------- 
set "CURRENT_DIR=%~dp0"
cd /d "%AGENT_PATH%"

REM check directory 
if %ERRORLEVEL% neq 0 (
  echo Cannot cd to !AGENT_PATH! 
  goto :ERROR_END
)

REM --------------------------------------- 
REM  Status Check of Sending-side Agent 
REM --------------------------------------- 
set /a COUNTER=1
:CHECK_SENDING-AGENT_STATUS
echo CHECK_SENDING-AGENT_STATUS

FOR /f "DELIMS=" %%i IN ('agentctl.bat -s status') DO SET SENDING-AGENT_STATUS=%%i 
echo RESULT: %SENDING-AGENT_STATUS% 

echo %SENDING-AGENT_STATUS% | findstr "000" 1>nul 
if %ERRORLEVEL%==0 (
  echo Starting the sending-side Agent.
  goto :START_SENDING-AGENT
)

echo %SENDING-AGENT_STATUS% | findstr "100" 1>nul 
if %ERRORLEVEL%==0 (
  echo Starting the sending-side Agent.
  goto :START_SENDING-AGENT
)

echo %SENDING-AGENT_STATUS% | findstr "255" 1>nul 
if %ERRORLEVEL%==0 (
  echo Starting the sending-side Agent.
  goto :START_SENDING-AGENT
)

goto :CHECK_RECEIVING-AGENT_STATUS


:START_SENDING-AGENT
call agentctl.bat -s start 
call :SLEEP
if !COUNTER! LSS !MAX_RETRY! (
  set /a COUNTER+=1 
  goto :CHECK_SENDING-AGENT_STATUS
) else (
  goto :ERROR_END
)


REM --------------------------------------- 
REM  Status Check of Receiving-side Agent 
REM --------------------------------------- 
set /a COUNTER=1
:CHECK_RECEIVING-AGENT_STATUS
echo CHECK_RECEIVING-AGENT_STATUS

FOR /f "DELIMS=" %%i IN ('agentctl.bat -r status') DO SET RECEIVING-AGENT_STATUS=%%i 
echo RESULT: %RECEIVING-AGENT_STATUS% 

echo %RECEIVING-AGENT_STATUS% | findstr "000" 1>nul 
if %ERRORLEVEL%==0 (
  echo Starting the receiving-side Agent.
  goto :START_RECEIVING-AGENT
)

echo %RECEIVING-AGENT_STATUS% | findstr "100" 1>nul 
if %ERRORLEVEL%==0  (
  echo Starting the receiving-side Agent.
  goto :START_RECEIVING-AGENT
)

echo %RECEIVING-AGENT_STATUS% | findstr "255" 1>nul 
if %ERRORLEVEL%==0 (
  echo Starting the receiving-side Agent.
  goto :START_RECEIVING-AGENT
)

goto :NORMAL_END

:START_RECEIVING-AGENT
call agentctl.bat -r start 
call :SLEEP
if !COUNTER! LSS !MAX_RETRY! (
  set /a COUNTER+=1
  goto CHECK_RECEIVING-AGENT_STATUS
) else (
  goto :ERROR_END
)

:NORMAL_END
cd /d %CURRENT_DIR% 
exit /B

:ERROR_END
echo Failed to start Agent.
exit /b -1

:SLEEP
ping -n 10 localhost > nul 
exit /B 0

#!/bin/bash 

# --------------------------------------- 
#  Settings 
# --------------------------------------- 
# Agent Installation Directory 
AGENT_PATH=~/webconnect-agent/bin
# Status Check Retry Max. Count
MAX_RETRY=10
# Wait Time
SLEEP_SEC=10

CURRENT_DIR=`pwd`
# --------------------------------------- 
#  functions 
# --------------------------------------- 
function error_end () {
  cd $CURRENT_DIR 
  echo Failed to start Agent.
}

# --------------------------------------- 
#  Initial Processing 
# --------------------------------------- 
# check directory 
if [ ! -e $AGENT_PATH ]; then 
  echo Cannot cd to $AGENT_PATH 
  error_end
  exit 1
fi 

cd $AGENT_PATH 
# --------------------------------------- 
#  Status Check of Sending-side Agent 
# --------------------------------------- 
COUNTER=1

function checkSendingAgentStatus () {
  echo checkSendingAgentStatus

  sendingAgentStatus=`./agentctl -s status`
  echo RESULT: $sendingAgentStatus 

  echo $sendingAgentStatus | grep -e 000 -e 100 -e 255 > /dev/null
  if [ $? -eq 0 ]; then 
    echo Starting the sending-side Agent.
    return 1
  fi 
  return 0
}

checkSendingAgentStatus
if [ $? -ne 0 ]; then 
  while [ $COUNTER -lt $MAX_RETRY ]
  do
    ./agentctl -s start
    sleep $SLEEP_SEC
    checkSendingAgentStatus
    if [ $? -eq 0 ]; then 
      break 
    fi 
    COUNTER=$((COUNTER + 1))
  done 

  if [ $COUNTER -ge $MAX_RETRY ]; then
    error_end
    exit 1
  fi 
fi 

# --------------------------------------- 
#  Status Check of Receiving-side Agent 
# --------------------------------------- 
COUNTER=1

function checkReceivingAgentStatus () {
  echo checkReceivingAgentStatus

  receivingAgentStatus=`./agentctl -r status`
  echo RESULT: $receivingAgentStatus 

  echo $receivingAgentStatus | grep -e 000 -e 100 -e 255 > /dev/null
  if [ $? -eq 0 ]; then 
    echo Starting the receiving-side Agent.
    return 1
  fi 
  return 0
}

checkReceivingAgentStatus
if [ $? -ne 0 ]; then 
  while [ $COUNTER -lt $MAX_RETRY ]
  do 
    ./agentctl -r start
    sleep $SLEEP_SEC
    checkReceivingAgentStatus
    if [ $? -eq 0 ]; then 
      break 
    fi 
    COUNTER=$((COUNTER + 1))
  done 
  
  if [ $COUNTER -ge $MAX_RETRY ]; then
    error_end
    exit 1
  fi 
fi 

cd $CURRENT_DIR