#!/bin/sh#Author: cym#2014-05-21#----------------How to use----------------##copy make_java.sh to /bin#chmod +x make_java.sh#monitorAgent_java.sh {start,stop,encode} mainfilename#eg:make_java.sh start test.java#------------------------------------------##JAVA_BIN=/home/admin/jdk1.7.0_55/bin/javaJAVA_BIN=/usr/local/jdk1.7.0_60/bin/java#MAINFILE=$2#MAIN_CLASS="com.cmsz.hostMonitor.rabbitMq.send.HostMonitorDatasMain"MAIN_CLASS="com.cmsz.monitor.agent.CollectAgentMain"path=$(dirname $0)APP_ID=$path"/OMCollectAgent.jar"#echo $APP_ID# return 0 or ppidgetPPID(){program=`ps -ef|grep $APP_ID|grep -v grep`if [ "$program" = "" ]; thenecho "-1"elselocal ppid=$(echo "$program" | awk {'print $2'})echo "$ppid"fi}startConnectionAgent(){echo $APP_IDlocal ppid=$(getPPID)if [ "$ppid" != "-1" ]; thenecho "WARN: $MAIN_CLASS is running!"return 1filocal jarFileLibs="."echo $JAVA_ARGS${JAVA_BIN} -cp $jarFileLibs:/usr/local/OMCollectAgent/lib/*:$APP_ID $MAIN_CLASS $JAVA_ARGSsleep 1ppid2=$(getPPID)echo $ppid2if [ "$ppid2" != "-1" ]; thenecho "INFO: Start $MAIN_CLASS successfully!"return 1elseecho "ERROR: Start $MAIN_CLASS failed! Please check again."return -1fi}stopConnectionAgent(){local ppid=$(getPPID)if [ "$ppid" = "-1" ]; thenecho "INFO: $MAIN_CLASS is not running!"return 0elsekill -9 $ppidsleep 3ppid=$(getPPID)if [ "$ppid" = "-1" ]; thenecho "INFO: Stop $MAIN_CLASS successfully."return 0elseecho "WARN: Could not stop $MAIN_CLASS. Please check again."return -1fifi}usage(){echo "usage:"echo " $PRG start"echo " $PRG stop"}#----------------------main----------------------## resolve links - $0 may be a softlinkPRG="$0"JAVA_ARGS="$2"echo $JAVA_ARGSwhile [ -h "$PRG" ]; dols=$(ls -ld "$PRG")link=$(expr "$ls" : '.*-> \(.*\)$')if expr "$link" : '/.*' > /dev/null; thenPRG="$link"elsePRG=$(dirname "$PRG")/"$link"fidoneecho $PRG# Get standard environment variables#PRGDIR=$(dirname "$2")#cd $PRGDIR#echo $PRGDIR#----------compile----------##------------run------------#case "$1" instart)startConnectionAgentexit $?;;stop)stopConnectionAgentexit $?;;*)echo "$1 in usage"usageexit $?;;esac
sh 执行 java cp_shell 脚本调用java进程
最新推荐文章于 2021-07-07 16:16:49 发布