startup.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/sh
  2. JAVA_HOME=$JAVA_HOME
  3. JAVA_OPTS=$JAVA_OPTS
  4. JAVA_VERSION=""
  5. ECHO_PREFIX="[DataGear] :"
  6. APP_MAIN="${productNameJar}"
  7. APP_PID=0
  8. echo " ____ _ ____ "
  9. echo " | _ \ __ _| |_ __ _ / ___| ___ __ _ _ __ "
  10. echo " | | | |/ _\` | __/ _\` | | _ / _ \/ _\` | '__|"
  11. echo " | |_| | (_| | |_ (_| | |_| | __/ (_| | | "
  12. echo " |____/ \__,_|\__\__,_|\____|\___|\__,_|_| "
  13. echo ""
  14. echo " DataGear-v${project.version} http://www.datagear.tech";
  15. echo ""
  16. if [ -n "$JAVA_HOME" ]; then
  17. echo "$ECHO_PREFIX using JAVA_HOME '$JAVA_HOME'"
  18. else
  19. java -version
  20. echo ""
  21. echo "$ECHO_PREFIX using previous java runtime"
  22. fi
  23. readAppPID()
  24. {
  25. if [ -n "$JAVA_HOME" ]; then
  26. JAVAPS=`$JAVA_HOME/bin/jps -l | grep "$APP_MAIN"`
  27. if [ -n "$JAVAPS" ]; then
  28. APP_PID=`echo $JAVAPS | awk '{print $1}'`
  29. else
  30. APP_PID=0
  31. fi
  32. else
  33. JAVAPS=`ps -ef | grep "$APP_MAIN" | grep -v grep`
  34. if [ -n "$JAVAPS" ]; then
  35. APP_PID=`echo $JAVAPS | awk '{print $2}'`
  36. else
  37. APP_PID=0
  38. fi
  39. fi
  40. }
  41. readAppPID
  42. if [ $APP_PID -ne 0 ]; then
  43. echo "$ECHO_PREFIX application is already running, PID is $APP_PID"
  44. echo "$ECHO_PREFIX starting [Failed]"
  45. else
  46. echo "$ECHO_PREFIX starting..."
  47. if [ -n "$JAVA_HOME" ]; then
  48. nohup $JAVA_HOME/bin/java $JAVA_OPTS -jar $APP_MAIN >/dev/null 2>&1 &
  49. else
  50. nohup java $JAVA_OPTS -jar $APP_MAIN >/dev/null 2>&1 &
  51. fi
  52. readAppPID
  53. if [ $APP_PID -ne 0 ]; then
  54. echo "$ECHO_PREFIX PID is $APP_PID"
  55. echo "$ECHO_PREFIX starting [OK]"
  56. else
  57. echo "$ECHO_PREFIX starting [Failed]"
  58. fi
  59. fi