run.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/bash
  2. # 配置参数
  3. JAVA_HOME="/usr/local/java/jdk";
  4. JAR_NAME="appservice.jar";
  5. JAR_PORT=8083
  6. JAVA_OPTS=" -server -Xmx1024m -Xms1024m -Duser.timezone=GMT+08 -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:MaxTenuringThreshold=15 -Xloggc:gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=dump/ -XX:ErrorFile=hss_err_pid<pid>.log"
  7. # 检查应用进程号,保存在psid变量
  8. psid=0
  9. checkpid() {
  10. javaps=`$JAVA_HOME/bin/jps -l | grep "\<${JAR_NAME}\>"`
  11. if [ -n "$javaps" ]; then
  12. psid=`echo $javaps | awk '{print $1}'`
  13. else
  14. psid=0
  15. fi
  16. }
  17. # 启动应用
  18. start() {
  19. checkpid
  20. if [ $psid -ne 0 ]; then
  21. echo "================================"
  22. echo "warn: $JAR_NAME already started! (pid=$psid)"
  23. echo "================================"
  24. else
  25. echo -n "Starting $JAR_NAME ..."
  26. nohup $JAVA_HOME/bin/java -jar $JAVA_OPTS $JAR_NAME --server.port=$JAR_PORT >nohup.out 2>&1 &
  27. checkpid
  28. if [ $psid -ne 0 ]; then
  29. echo "(pid=$psid) [OK]"
  30. else
  31. echo "[Failed]"
  32. fi
  33. fi
  34. }
  35. # 停止应用
  36. stop() {
  37. checkpid
  38. if [ $psid -ne 0 ]; then
  39. echo -n "Stopping $JAR_NAME ...(pid=$psid) "
  40. kill -15 $psid
  41. if [ $? -eq 0 ]; then
  42. echo "[OK]"
  43. else
  44. echo "[Failed]"
  45. fi
  46. sleep 1
  47. checkpid
  48. if [ $psid -ne 0 ]; then
  49. stop
  50. fi
  51. else
  52. echo "================================"
  53. echo "warn: $JAR_NAME is not running"
  54. echo "================================"
  55. fi
  56. }
  57. case $1 in
  58. start)
  59. echo "start project......"
  60. start
  61. ;;
  62. stop)
  63. echo "stop project......"
  64. stop
  65. ;;
  66. restart)
  67. echo "restart project......"
  68. stop
  69. start
  70. ;;
  71. *)
  72. esac
  73. exit 0