run.sh 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/bin/bash
  2. #NOT READY,PLEASE REFINE THIS
  3. working_directory=$(pwd)
  4. proc_watcher="yes"
  5. if [ "$1" == "--no-watch" ]; then
  6. proc_watcher="no"
  7. shift
  8. fi
  9. echo $4
  10. executeJava=
  11. if [ -d "$4" ]; then
  12. export JAVA_HOME=$4
  13. export JRE_HOME=$JAVA_HOME/jre
  14. export PATH=$JAVA_HOME/bin:$PATH
  15. export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
  16. executeJava="java"
  17. fi
  18. if [ -z $executeJava ];then
  19. javaHomeArray=(/opt/jdk1.7.0_45 /opt/jdk1.7.0_65 /opt/jdk1.7.0_71 /opt/jdk1.7.0_79 /opt/jdk1.7.0_80 /opt/jdk1.8.0_77 /opt/jdk1.8.0_121 /opt/jdk1.8.0_131 /app/jdk1.7.0_79 /app/jdk1.7.0_80)
  20. for jhome in ${javaHomeArray[@]}
  21. do
  22. tmp="$jhome/bin/java"
  23. if [ -x "$tmp" ]; then
  24. executeJava=$tmp
  25. break
  26. fi
  27. done
  28. fi
  29. JAVA_VERSION=`java -version 2>&1 |awk 'NR==1{ gsub(/"/,""); print $3 }'`
  30. if [[ ${JAVA_VERSION:0:1} -eq "9" ]];then
  31. export JRE_HOME=$JAVA_HOME
  32. fi
  33. echo "using $executeJava"
  34. netcardIndex=
  35. netcardName=
  36. if [ $# -gt 2 ]; then
  37. if [[ $3 =~ ^[0-9]$ ]]; then
  38. netcardIndex=$3
  39. else
  40. netcardName=$3
  41. fi
  42. fi
  43. cd ..
  44. export CLASSPATH=bin/com.creditease.uav.base-1.0-boot.jar
  45. echo $CLASSPATH
  46. javaAgent="-javaagent:../uavmof/com.creditease.uav.agent/com.creditease.uav.monitorframework.agent-1.0-agent.jar"
  47. if [[ ${JAVA_VERSION:0:1} -eq "9" ]];then
  48. javaOpts="-server -Xms64m -Xmx256m -Xss256k -Djdk.attach.allowAttachSelf=true -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=."
  49. else
  50. javaOpts="-server -Xms64m -Xmx256m -Xss256k -XX:-UseSplitVerifier -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing -XX:CMSIncrementalDutyCycleMin=0 -XX:CMSIncrementalDutyCycle=10 -XX:+UseParNewGC -XX:+UseCMSCompactAtFullCollection -XX:-CMSParallelRemarkEnabled -XX:CMSFullGCsBeforeCompaction=0 -XX:CMSInitiatingOccupancyFraction=70 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=."
  51. fi
  52. #javaOpts="-server -Xms64m -Xmx256m -Xss256k -XX:-UseSplitVerifier -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing -XX:CMSIncrementalDutyCycleMin=0 -XX:CMSIncrementalDutyCycle=10 -XX:+UseParNewGC -XX:+UseCMSCompactAtFullCollection -XX:-CMSParallelRemarkEnabled -XX:CMSFullGCsBeforeCompaction=0 -XX:CMSInitiatingOccupancyFraction=70 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=."
  53. $executeJava $javaAgent $javaOpts -XX:OnOutOfMemoryError='kill -9 %p' -DNetCardIndex=$netcardIndex -DNetCardName=$netcardName -DJAppID=$2 -DJAppGroup=UAV -classpath $CLASSPATH com.creditease.mscp.boot.MSCPBoot -p $1 &
  54. # add crontab process watcher
  55. if [ "$proc_watcher" == "yes" ]; then
  56. sleep 1
  57. # add crontab
  58. cronfile=/tmp/$1".tmp"
  59. crontab -l | grep -v "$1" 1>$cronfile 2>/dev/null
  60. echo "*/1 * * * * sh $working_directory/uav_proc_watcher.sh \"$1\" \"$working_directory\" \"./run.sh --no-watch $1 $2 $3 $4\" >/dev/null 2>&1" >> $cronfile
  61. crontab $cronfile
  62. rm -rf $cronfile
  63. exit 0
  64. fi