当前位置:   article > 正文

jar包启动脚本_jar 启动脚本

jar 启动脚本

run.sh

  1. if [ -z "$1" ] || [ -z "$2" ]
  2. then
  3. echo "需按规范传参,实例: "
  4. echo "./run.sh xx.jar status"
  5. exit
  6. fi
  7. OJECT_DATE=$(date +%Y%m%d%H%M%S)
  8. #
  9. #当前文件目录
  10. BASE_HOME=$(cd $(dirname $0); pwd)
  11. #
  12. PROJECT_NAME=$1
  13. #
  14. #PROJECT_OPTS="-Dbuildv=${PROJECT_DATE} -Xmx512m -Djava.compiler=NONE -Dspring.profiles.active=prod"
  15. PROJECT_OPTS=""
  16. #
  17. PIDS=`ps -ef | grep "${PROJECT_NAME}" | grep java |awk '{print $2}'`
  18. count=$(ps -ef | grep "${PROJECT_NAME}" | grep "java" | wc -l)
  19. status(){
  20. echo "==========status======="
  21. ps -ef | grep "${PROJECT_NAME}" | grep java
  22. if [ $count -le 0 ]; then
  23. echo ${PROJECT_NAME}" is not runing"
  24. else
  25. echo ${PROJECT_NAME}" is runing"
  26. fi
  27. }
  28. start() {
  29. echo "==========start===========";
  30. ps -ef | grep "${PROJECT_NAME}" | grep java
  31. count=$(ps -ef | grep "${PROJECT_NAME}" | grep "java" | wc -l)
  32. if [ $count -le 0 ]; then
  33. echo ${PROJECT_NAME}" is starting"
  34. cd $BASE_HOME
  35. nohup java $PROJECT_OPTS -jar ${PROJECT_NAME} >/dev/null 2>&1 &
  36. else
  37. echo ${PROJECT_NAME}" is runing"
  38. fi
  39. }
  40. stop() {
  41. echo "===========stop============";
  42. ps -ef | grep "${PROJECT_NAME}" | grep java
  43. if [ -z "$PIDS" ]; then
  44. echo "警告: ${PROJECT_NAME} 未启动!"
  45. exit 1
  46. fi
  47. echo -e "正在停止 ${PROJECT_NAME} 进程[PIDS] ...\c"
  48. for PID in $PIDS ; do
  49. kill $PID > /dev/null 2>&1
  50. done
  51. COUNT=0
  52. while [ $COUNT -lt 1 ]; do
  53. echo -e "......\c"
  54. sleep 2
  55. COUNT=1
  56. for PID in $PIDS ; do
  57. PID_EXIST=`ps -f -p $PID | grep java`
  58. if [ -n "$PID_EXIST" ]; then
  59. COUNT=0
  60. break
  61. fi
  62. done
  63. done
  64. echo "${PROJECT_NAME} 进程[PIDS], 已停止!"
  65. }
  66. restart() {
  67. stop;
  68. echo "sleeping.........";
  69. sleep 3;
  70. start;
  71. }
  72. case "$2" in
  73. 'start')
  74. start
  75. ;;
  76. 'stop')
  77. stop
  78. ;;
  79. 'status')
  80. status
  81. ;;
  82. 'restart')
  83. restart
  84. ;;
  85. *)
  86. echo "usage: $0 {start|stop|restart|status}"
  87. exit 1
  88. ;;
  89. esac

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/76393?site
推荐阅读
相关标签
  

闽ICP备14008679号