query.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #!/bin/sh
  2. ROOT=$(cd `dirname $0`/../../; pwd)
  3. cd $ROOT
  4. APP_NAME=blackbox-query
  5. JAVA_HOME=$ROOT/jdk8
  6. JAR_NAME=$ROOT/lib/query-app-0.0.1-SNAPSHOT.jar
  7. #PID 代表是PID文件
  8. PID=$ROOT/pid/$APP_NAME\.pid
  9. usage() {
  10. echo "Usage: sh 执行脚本.sh [start|stop|restart|status|force_stop]"
  11. exit 1
  12. }
  13. #检查程序是否在运行
  14. is_exist(){
  15. pid=`ps -ef|grep $JAR_NAME|grep -v grep|awk '{print $2}' `
  16. #如果不存在返回1,存在返回0
  17. if [ -z "${pid}" ]; then
  18. return 1
  19. else
  20. return 0
  21. fi
  22. }
  23. #启动方法,--spring.profiles.active=prod0设置启动prod0环境
  24. start(){
  25. is_exist
  26. if [ $? -eq "0" ]; then
  27. echo ">>> ${JAR_NAME} is already running PID=${pid} <<<"
  28. else
  29. #nohup $JAVA_HOME/bin/java -Xms64m -Xmx1024m -Xss512K -Dspring.config.additional-location=conf/application-query.yml -jar $JAR_NAME > /dev/null 2>&1 &
  30. nohup $JAVA_HOME/bin/java -Xms64m -Xmx1024m -Xss512K -Dspring.config.additional-location=conf/application-query.yml -jar $JAR_NAME >> ./logs/query.log 2>&1 &
  31. #java -Xms64m -Xmx1024m -Xss512K -Dspring.config.additional-location=conf/application-query.yml -jar $JAR_NAME
  32. echo $! > $PID
  33. echo ">>> start $JAR_NAME successed PID=$! <<<"
  34. fi
  35. }
  36. #停止方法
  37. stop(){
  38. #is_exist
  39. pidf=$(cat $PID)
  40. #echo "$pidf"
  41. echo ">>> APP PID = $pidf begin kill $pidf <<<"
  42. kill $pidf
  43. rm -rf $PID
  44. sleep 3
  45. is_exist
  46. if [ $? -eq "0" ]; then
  47. echo ">>> api 2 PID = $pid begin kill -9 $pid <<<"
  48. kill -9 $pid
  49. sleep 2
  50. echo ">>> $JAR_NAME process stopped <<<"
  51. else
  52. echo ">>> ${JAR_NAME} is not running <<<"
  53. fi
  54. }
  55. force_stop(){
  56. #is_exist
  57. pidf=$(cat $PID)
  58. #echo "$pidf"
  59. echo ">>> APP PID = $pidf begin kill $pidf <<<"
  60. kill -9 $pidf
  61. rm -rf $PID
  62. sleep 3
  63. is_exist
  64. if [ $? -eq "0" ]; then
  65. echo ">>> api 2 PID = $pid begin kill -9 $pid <<<"
  66. kill -9 $pid
  67. sleep 2
  68. echo ">>> $JAR_NAME process stopped <<<"
  69. else
  70. echo ">>> ${JAR_NAME} is not running <<<"
  71. fi
  72. }
  73. #输出运行状态
  74. status(){
  75. is_exist
  76. if [ $? -eq "0" ]; then
  77. echo ">>> ${JAR_NAME} is running PID is ${pid} <<<"
  78. else
  79. echo ">>> ${JAR_NAME} is not running <<<"
  80. fi
  81. }
  82. #重启
  83. restart(){
  84. stop
  85. start
  86. }
  87. #根据输入参数,选择执行对应方法,不输入则执行使用说明
  88. case "$1" in
  89. "start")
  90. start
  91. ;;
  92. "stop")
  93. stop
  94. ;;
  95. "status")
  96. status
  97. ;;
  98. "restart")
  99. restart
  100. ;;
  101. "force_stop")
  102. force_stop
  103. ;;
  104. *)
  105. usage
  106. ;;
  107. esac
  108. exit 0