You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
1.4 KiB

  1. #!/usr/bin/env bash
  2. INPUT=$2
  3. FILE_PATH=`readlink -f ${INPUT}`
  4. SERVICE=${INPUT##*/}
  5. SERVICE_NAME=${SERVICE%.*}
  6. DEPLOY_DIR=`pwd`
  7. JVM_OPTS="-server -Xms64m -Xmx128m"
  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 [[ "$SERVICE" = "" ]];
  14. then
  15. echo -e "\033[0;31m 未输入应用名 \033[0m"
  16. exit 1
  17. fi
  18. LOGS_DIR="$DEPLOY_DIR/logs/$SERVICE_NAME"
  19. echo "$LOGS_DIR"
  20. if [[ ! -d "$LOGS_DIR" ]]; then
  21. mkdir -p ${LOGS_DIR}
  22. fi
  23. LOG_PATH="$LOGS_DIR/stdout.out"
  24. pid=0
  25. start()
  26. {
  27. checkPid
  28. if [[ ! -n "$pid" ]]; then
  29. BUILD_ID=dontKillMe nohup java ${JVM_OPTS} -jar ${FILE_PATH} --spring.profiles.active=prod >> ${LOG_PATH} 2>&1 &
  30. echo "$SERVICE_NAME is starting you can check the $LOG_PATH"
  31. else
  32. echo "$SERVICE_NAME is runing PID: $pid"
  33. fi
  34. }
  35. checkPid()
  36. {
  37. pid=`ps -ef |grep ${FILE_PATH} |grep -v grep |awk '{print $2}'`
  38. }
  39. stop()
  40. {
  41. checkPid
  42. if [[ ! -n "$pid" ]]; then
  43. echo "$SERVICE_NAME not runing"
  44. else
  45. echo "$SERVICE_NAME stop..."
  46. kill -9 ${pid}
  47. fi
  48. }
  49. restart()
  50. {
  51. stop
  52. sleep 2
  53. start
  54. }
  55. status()
  56. {
  57. checkPid
  58. if [[ ! -n "$pid" ]]; then
  59. echo "$SERVICE_NAME not runing"
  60. else
  61. echo "$SERVICE_NAME runing PID: $pid"
  62. fi
  63. }
  64. case $1 in
  65. start) start;;
  66. stop) stop;;
  67. restart) restart;;
  68. status) status;;
  69. *) echo "require start|stop|restart|status" ;;
  70. esac