jrun.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/env bash
  2. current_dir=$(cd "$(dirname "$0")"; pwd)
  3. cd $current_dir
  4. HOME=$current_dir
  5. #JAVA_HOME=/opt/jdk1.7.0_07
  6. MAINCLASS="org.eclipse.jetty.start.Main"
  7. LIB_DIR="lib"
  8. CLASS_DIR="start.jar"
  9. JVM_ARGS="-Djetty.port=6220 -Dsolr.solr.home=solr -Dorg.eclipse.jetty.util.URI.charset=UTF-8"
  10. PRO_ARGS=""
  11. PROGRAM_NAME=solr
  12. PID_DIR="$HOME/start.d"
  13. jcommand="java"
  14. runtype="-classpath"
  15. APPEND_LIB=$HOME"/"$CLASS_DIR
  16. PID_NAME=$PROGRAM_NAME".pid"
  17. pid=$PID_DIR/$PID_NAME
  18. echo "CURRENT_DIR="$HOME
  19. #注意这个字符,不是',是`,数字键左边的那个键
  20. filelist=`ls $HOME"/"$LIB_DIR`
  21. for f in $filelist
  22. do
  23. name=$HOME"/"$LIB_DIR"/"$f
  24. APPEND_LIB=$APPEND_LIB:$name
  25. done
  26. case $1 in
  27. 'start' )
  28. mkdir -p "$PID_DIR"
  29. if [ -f "$pid" ]; then
  30. echo $pid existsed, pid: `cat $pid`
  31. if kill -0 `cat "$pid"` > /dev/null 2>&1; then
  32. echo $PROGRAM_NAME running as process `cat $pid`. Stop it first.
  33. exit 1
  34. fi
  35. fi
  36. echo -n 'Starting : '
  37. if $jcommand $JVM_ARGS $runtype $APPEND_LIB $MAINCLASS $PRO_ARGS > /dev/null 2>&1 &
  38. then
  39. echo $! > "$pid"
  40. echo 'OK'
  41. else
  42. echo 'Failed'
  43. fi
  44. ;;
  45. 'run' )
  46. $jcommand $JVM_ARGS $runtype $APPEND_LIB $MAINCLASS $PRO_ARGS
  47. ;;
  48. 'classpath' )
  49. echo $jcommand $JVM_ARGS $runtype $APPEND_LIB $MAINCLASS $PRO_ARGS
  50. ;;
  51. 'stop' )
  52. if [ -f "$pid" ]; then
  53. if kill `cat "$pid"` > /dev/null 2>&1; then
  54. echo stopping $PROGRAM_NAME
  55. kill `cat "$pid"`
  56. rm $pid
  57. else
  58. echo No $PROGRAM_NAME to stop
  59. fi
  60. else
  61. echo No $PROGRAM_NAME to stop
  62. fi
  63. ;;
  64. 'list' )
  65. ps aux | egrep '(PID|java|$PROGRAM_NAME)'
  66. ;;
  67. *)
  68. echo 'usage: `basename $0` {start|run|stop|list}'
  69. esac