insert.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/bin/sh
  2. ROOT=$(cd `dirname $0`/../../; pwd)
  3. cd $ROOT
  4. APP_NAME=blackbox-insert
  5. JAVA_HOME=$ROOT/jdk8
  6. JAR_NAME=$ROOT/lib/insert-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. java -Xms64m -Xmx1024m -Xss512K -Dspring.config.additional-location=conf/application-insert.yml -jar $JAR_NAME
  30. echo $! > $PID
  31. echo ">>> start $JAR_NAME successed PID=$! <<<"
  32. fi
  33. }
  34. #停止方法
  35. stop(){
  36. #is_exist
  37. pidf=$(cat $PID)
  38. #echo "$pidf"
  39. echo ">>> APP PID = $pidf begin kill $pidf <<<"
  40. kill $pidf
  41. rm -rf $PID
  42. sleep 3
  43. is_exist
  44. if [ $? -eq "0" ]; then
  45. echo ">>> api 2 PID = $pid begin kill -9 $pid <<<"
  46. kill -9 $pid
  47. sleep 2
  48. echo ">>> $JAR_NAME process stopped <<<"
  49. else
  50. echo ">>> ${JAR_NAME} is not running <<<"
  51. fi
  52. }
  53. force_stop(){
  54. #is_exist
  55. pidf=$(cat $PID)
  56. #echo "$pidf"
  57. echo ">>> APP PID = $pidf begin kill $pidf <<<"
  58. kill -9 $pidf
  59. rm -rf $PID
  60. sleep 3
  61. is_exist
  62. if [ $? -eq "0" ]; then
  63. echo ">>> api 2 PID = $pid begin kill -9 $pid <<<"
  64. kill -9 $pid
  65. sleep 2
  66. echo ">>> $JAR_NAME process stopped <<<"
  67. else
  68. echo ">>> ${JAR_NAME} is not running <<<"
  69. fi
  70. }
  71. #输出运行状态
  72. status(){
  73. is_exist
  74. if [ $? -eq "0" ]; then
  75. echo ">>> ${JAR_NAME} is running PID is ${pid} <<<"
  76. else
  77. echo ">>> ${JAR_NAME} is not running <<<"
  78. fi
  79. }
  80. #重启
  81. restart(){
  82. stop
  83. start
  84. }
  85. #根据输入参数,选择执行对应方法,不输入则执行使用说明
  86. case "$1" in
  87. "start")
  88. start
  89. ;;
  90. "stop")
  91. stop
  92. ;;
  93. "status")
  94. status
  95. ;;
  96. "restart")
  97. restart
  98. ;;
  99. "force_stop")
  100. restart
  101. ;;
  102. *)
  103. usage
  104. ;;
  105. esac
  106. exit 0