probeConsole.sh 1.9 KB

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