osf-hub.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/usr/bin/env bash
  2. #JAVA_HOME=/opt/jdk1.7.0_07
  3. if [ -z "${APP_HOME}" ]; then
  4. export APP_HOME="$(cd "`dirname "$0"`"/..; pwd)"
  5. fi
  6. # Find the java binary
  7. if [ -n "${JAVA_HOME}" ]; then
  8. RUNNER="${JAVA_HOME}/bin/java"
  9. else
  10. if [ `command -v java` ]; then
  11. RUNNER="java"
  12. else
  13. echo "JAVA_HOME is not set" >&2
  14. exit 1
  15. fi
  16. fi
  17. cd $APP_HOME
  18. # -----------------------------------------------------------
  19. # For a full list of available configuration files do
  20. # java -jar start.jar --help
  21. # -----------------------------------------------------------
  22. if [ ! -d $APP_HOME/logs ]
  23. then
  24. mkdir -p $APP_HOME/logs
  25. fi
  26. echo "dir_path="$dir_path
  27. MAINCLASS="com.jiusuo.osf.hub.Main"
  28. LIB_DIR="lib"
  29. CLASS_DIR="conf"
  30. JVM_ARGS="$JAVA_OPTS -Dapp.home=$APP_HOME -Dapp.logs=$APP_HOME/logs"
  31. PRO_ARGS=""
  32. PROGRAM_NAME="fsserver"
  33. PID_DIR="$APP_HOME/start.d"
  34. jcommand=$RUNNER
  35. runtype="-classpath"
  36. APPEND_LIB="$APP_HOME/$CLASS_DIR"
  37. PID_NAME="$PROGRAM_NAME.pid"
  38. pid=$PID_DIR/$PID_NAME
  39. echo "CURRENT_DIR="$APP_HOME
  40. filelist=`ls $APP_HOME"/"$LIB_DIR"/"*.jar`
  41. for f in $filelist
  42. do
  43. name=$f
  44. APPEND_LIB=$APPEND_LIB:$name
  45. done
  46. case $1 in
  47. 'start' )
  48. mkdir -p "$PID_DIR"
  49. if [ -f "$pid" ]; then
  50. echo $pid existsed, pid: `cat $pid`
  51. if kill -0 `cat "$pid"` > /dev/null 2>&1; then
  52. echo $PROGRAM_NAME running as process `cat $pid`. Stop it first.
  53. exit 1
  54. fi
  55. fi
  56. echo -n 'Starting : '
  57. if $jcommand $JVM_ARGS $runtype $APPEND_LIB $MAINCLASS $PRO_ARGS > /dev/null 2>&1 &
  58. then
  59. echo $! > "$pid"
  60. echo 'OK'
  61. else
  62. echo 'Failed'
  63. fi
  64. ;;
  65. 'run' )
  66. $jcommand $JVM_ARGS $runtype $APPEND_LIB $MAINCLASS $PRO_ARGS
  67. ;;
  68. 'classpath' )
  69. echo $jcommand $JVM_ARGS $runtype $APPEND_LIB $MAINCLASS $PRO_ARGS
  70. ;;
  71. 'stop' )
  72. if [ -f "$pid" ]; then
  73. if kill `cat "$pid"` > /dev/null 2>&1; then
  74. echo stopping $PROGRAM_NAME
  75. kill `cat "$pid"`
  76. rm $pid
  77. else
  78. echo No $PROGRAM_NAME to stop
  79. fi
  80. else
  81. echo No $PROGRAM_NAME to stop
  82. fi
  83. ;;
  84. 'restart' )
  85. ${0} stop
  86. ${0} start
  87. ;;
  88. 'list' )
  89. ps aux | egrep '(PID|java|$PROGRAM_NAME)'
  90. ;;
  91. *)
  92. echo 'usage: `basename $0` {start|run|stop|list}'
  93. esac