javarun.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/usr/bin/env bash
  2. SP_MIN_MEM=512m
  3. SP_MAX_MEM=1024m
  4. SCRIPT="$0"
  5. # SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path.
  6. while [ -h "$SCRIPT" ] ; do
  7. ls=`ls -ld "$SCRIPT"`
  8. # Drop everything prior to ->
  9. link=`expr "$ls" : '.*-> \(.*\)$'`
  10. if expr "$link" : '/.*' > /dev/null; then
  11. SCRIPT="$link"
  12. else
  13. SCRIPT=`dirname "$SCRIPT"`/"$link"
  14. fi
  15. done
  16. # some Java parameters
  17. JAVA=`which java 2>/dev/null`
  18. if [[ $JAVA_HOME != "" ]]; then
  19. JAVA=$JAVA_HOME/bin/java
  20. fi
  21. if test -z "$JAVA"; then
  22. echo "No java found in the PATH. Please set JAVA_HOME."
  23. exit 1
  24. fi
  25. INTG_HOME=`dirname "$SCRIPT"`/..
  26. export INTG_HOME=`cd "$INTG_HOME"; pwd`
  27. SP_CLASSPATH=$INTG_HOME/conf:$INTG_HOME/lib/*
  28. MAIN_CLASS="com.yiidata.intergration.web.IntgApplication"
  29. DEF_APP_NAME="intg-server"
  30. #java opts config
  31. SP_OPTS="-Dapp.home=$INTG_HOME -Djava.library.path=$INTG_HOME/conf"
  32. SP_OPTS="$SP_OPTS -Djetty.home=$INTG_HOME"
  33. SP_OPTS="$SP_OPTS -Xms${SP_MIN_MEM} -Xmx${SP_MAX_MEM}"
  34. if [ ! -d "$INTG_HOME/logs" ]
  35. then
  36. mkdir -p $INTG_HOME/logs
  37. fi
  38. COMMAND=$1
  39. start(){
  40. echo "starting $DEF_APP_NAME ..."
  41. nohup $JAVA $SP_OPTS -cp $SP_CLASSPATH $MAIN_CLASS >/dev/null 2>&1 &
  42. echo "please see the log --> '$INTG_HOME/logs/$DEF_APP_NAME.log' or 'ps -ef|grep Application'"
  43. echo "$DEF_APP_NAME has started! "
  44. }
  45. run(){
  46. echo "run $DEF_APP_NAME server..."
  47. $JAVA $SP_OPTS -cp $SP_CLASSPATH $MAIN_CLASS
  48. }
  49. stop(){
  50. echo "stop ..."
  51. warningpid=`jps -l|grep $MAIN_CLASS | cut -f 1 -d " "`
  52. echo "$MAIN_CLASS process's pid is $warningpid"
  53. if [ $warningpid ]
  54. then
  55. jps -l|grep $MAIN_CLASS | cut -f 1 -d " " |xargs kill -15
  56. echo "$MAIN_CLASS [$warningpid] is stoped!"
  57. else
  58. echo "$MAIN_CLASS stop failed!"
  59. fi
  60. }
  61. status(){
  62. warningpid=`jps -l|grep $MAIN_CLASS | cut -f 1 -d " "`
  63. if [ $warningpid ]
  64. then
  65. echo "$MAIN_CLASS [$warningpid] is running "
  66. else
  67. echo "$MAIN_CLASS is not running"
  68. fi
  69. }
  70. docommand() {
  71. case "$COMMAND" in
  72. 'start')
  73. start
  74. ;;
  75. 'run')
  76. run
  77. ;;
  78. 'stop')
  79. stop
  80. ;;
  81. 'restart')
  82. stop;
  83. sleep 5
  84. start;
  85. ;;
  86. 'status')
  87. status
  88. ;;
  89. *)
  90. echo "usage: [start|run|stop|restart|status|log]"
  91. ;;
  92. esac
  93. }
  94. docommand "$@"
  95. exit 0