ry.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/bash
  2. AppName=dgtly.jar
  3. #JVM参数
  4. JVM_OPTS="-Dname=$AppName -Duser.timezone=Asia/Shanghai -Xms512M -Xmx512M -XX:PermSize=256M -XX:MaxPermSize=512M -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:NewRatio=1 -XX:SurvivorRatio=30 -XX:+UseParallelGC -XX:+UseParallelOldGC"
  5. APP_HOME=`pwd`
  6. LOG_PATH=$APP_HOME/logs/$AppName.log
  7. if [ "$1" = "" ];
  8. then
  9. echo -e "\033[0;31m 未输入操作名 \033[0m \033[0;34m {start|stop|restart|status} \033[0m"
  10. exit 1
  11. fi
  12. if [ "$AppName" = "" ];
  13. then
  14. echo -e "\033[0;31m 未输入应用名 \033[0m"
  15. exit 1
  16. fi
  17. function start()
  18. {
  19. PID=`ps -ef |grep java|grep $AppName|grep -v grep|awk '{print $2}'`
  20. if [ x"$PID" != x"" ]; then
  21. echo "$AppName is running..."
  22. else
  23. nohup java -jar $JVM_OPTS target/$AppName > /dev/null 2>&1 &
  24. echo "Start $AppName success..."
  25. fi
  26. }
  27. function stop()
  28. {
  29. echo "Stop $AppName"
  30. PID=""
  31. query(){
  32. PID=`ps -ef |grep java|grep $AppName|grep -v grep|awk '{print $2}'`
  33. }
  34. query
  35. if [ x"$PID" != x"" ]; then
  36. kill -TERM $PID
  37. echo "$AppName (pid:$PID) exiting..."
  38. while [ x"$PID" != x"" ]
  39. do
  40. sleep 1
  41. query
  42. done
  43. echo "$AppName exited."
  44. else
  45. echo "$AppName already stopped."
  46. fi
  47. }
  48. function restart()
  49. {
  50. stop
  51. sleep 2
  52. start
  53. }
  54. function status()
  55. {
  56. PID=`ps -ef |grep java|grep $AppName|grep -v grep|wc -l`
  57. if [ $PID != 0 ];then
  58. echo "$AppName is running..."
  59. else
  60. echo "$AppName is not running..."
  61. fi
  62. }
  63. case $1 in
  64. start)
  65. start;;
  66. stop)
  67. stop;;
  68. restart)
  69. restart;;
  70. status)
  71. status;;
  72. *)
  73. esac