#!/bin/bash

# This script checks if a Java app is running with class specified as the argument
# e.g.  /cyflex/cmds/trs/CheckJavaApp com.cybermetrix.trs.trc.TRCDaemon
# It returns 0 if it is running and 1 if it is not.

__find_java_app()
{
   /bin/ps axh -o pid,cmd | while read pid cmd; do
      echo "$cmd" | grep java | grep "$1" > /dev/null;
      [ $? -eq 0 ] && echo $pid;
   done
}

# Give 1 second for the app to be established if it is new.
sleep 1

pid=`__find_java_app $1`
if [ -z "$pid" ]; then
    exit 1;
else
    exit 0;
fi
