ry.sh 1.6 KB

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