bwcole

DataPower Agent - how to stop

Discussion created by bwcole on Jan 23, 2018
Latest reply on Jan 23, 2018 by Hallett_German

After getting the DataPower agent functional, found that the "DatapowerMonitor.sh" is unlike other agent scripts with no included "stop", "start" and "status" parameter option.

 

The agent really need to be a well behaved server citizen by providing a way to request the agent status, start and stop options without having to add agent logic to the request.

 

So, to solve this, I copied the EPACtrl.sh script from 10, then changed out the internals for the datapower agent.

 

This agent will be replace in 10.7 or after with the Infrastructure agent, so everything changes.

 

Hope this will be helpful,

#
# DPACtrl.sh
# Control script for running the Introscope EP Agent
# as a Unix service via an easy-to-use command line interface.
# Usage:
# DPACtrl.sh start
# DPACtrl.sh status
# DPACtrl.sh stop
# DPACtrl.sh help
#
# The exit codes returned are:
#       0 - operation completed successfully
#       1 -
#       2 - usage error
#       3 - DPAgent could not be started
#       4 - DPAgent could not be stopped
#       8 - configuration syntax error
#
# When multiple arguments are given, only the error from the _last_
# argument is reported.
# Run "DPACtrl.sh help" for usage info

# |||||||||||||||||||| START CONFIGURATION SECTION  ||||||||||||||||||||
ERROR=0

SCRIPTPATH=`pwd`
AGENTHOME=`dirname $SCRIPTPATH`

LIB=$AGENTHOME/lib
CONFIG=$AGENTHOME/config

# The logfile
LOGFILE="${AGENTHOME}/logs/DataPower.log"
# the path to your PID file
PIDFILE="${AGENTHOME}/bin/dpa.pid"


# changes for passing heap values in arguments
MIN_HEAP_VAL_IN_MB=20
MAX_HEAP_VAL_IN_MB=256

# the command to start the EPAgent
DPACmd="java -Xms${MIN_HEAP_VAL_IN_MB}m -Xmx${MAX_HEAP_VAL_IN_MB}m -cp $LIB/Agent-10.5.1.6.jar:$LIB/avalon-framework-4.1.3.jar:$LIB/commons-beanutils-1.7.0.jar:$LIB/commons-codec-1.2.jar:$LIB/commons-digester-1.8.jar:$LIB/commons-httpclient-3.1.jar:$LIB/commons-io-1.3.2.jar:$LIB/commons-logging-1.1.jar:$LIB/datapower-4.0.0.jar:$LIB/dom4j-1.3.jar:$LIB/jackson-core-2.7.6.jar:$LIB/log4j-1.2.12.jar:$LIB/logkit-1.0.1.jar:$LIB/servlet-api-2.3.jar -Dcom.wily.introscope.agentProfile=$CONFIG/datapower.properties -Dapp.name="DatapowerMonitor" com.wily.field.dpmon.DataPowerMonitor -c $CONFIG/DatapowerMonitor-config.xml"
#echo $DPACmd
# ||||||||||||||||||||   END CONFIGURATION SECTION  ||||||||||||||||||||


ARGV="$@"
if [ "x$ARGV" = "x" ] ; then
    ARGS="help"
fi

#echo $PIDFILE

for ARG_RAW in $@ $ARGS
do
    # check for pidfile
    if [ -f "$PIDFILE" ] ; then
        PID=`cat "$PIDFILE"`
#echo $PID

        if [ "x$PID" != "x" ] && kill -0 $PID 2>/dev/null ; then
            STATUS="DPAgent (pid $PID) running"
            RUNNING=1
        else
            STATUS="DPAgent (pid $PID) not running"
            RUNNING=0
        fi
    else
        STATUS="DPAgent (no pid file) not running"
        RUNNING=0
    fi

    if [ $ERROR -eq 2 ]
      then
        ARG="help"
        #echo  VALUE CHANGED to help: $ARG
      else
        ARG=${ARG_RAW}
        #echo  VALUE CHANGED to actual: $ARG
    fi

    case $ARG in
      status)
        if [ $RUNNING -eq 1 ]; then
                echo "$0 $ARG:  Agent is running"
        else
                echo "$0 $ARG:  Agent is stopped"
        fi
        ;;
    start)

        if [ $RUNNING -eq 1 ]; then
            echo "$0 $ARG: DPAgent (pid $PID) already running"
            continue
        fi
        nohup $DPACmd >> "$LOGFILE" 2>&1 &
        if [ "x$!" != "x" ] ; then
            echo "$!" > "$PIDFILE"
            echo "$0 $ARG: DPAgent started"
            break;
        else
            echo "$0 $ARG: DPAgent could not be started"
            ERROR=3
        fi
        ;;
    stop)
        if [ $RUNNING -eq 0 ]; then
            echo "$0 $ARG: $STATUS"
            continue
        fi
        if kill $PID ; then
            rm "$PIDFILE"
           
            echo "$0 $ARG: DPAgent stopped"
        else
            echo "$0 $ARG: DPAgent could not be stopped"
            ERROR=4
        fi
        ;;
    *)
        echo "usage: $0 (start|stop|status|help) [min java heap] [max java heap]"
        cat <<EOF
where
     start                      - start EPAgent
     stop                       - stop EPAgent
     status                     - status of DPAgent
     help                       - this screen

EOF
        ERROR=2
    ;;

    esac
    break
done

exit $ERROR

Outcomes