stand-alone chmod -R 777 xx.sh vim xx.sh :set ff=unix

Start & Stop

  1. #!/bin/bash
  2. # PROJECT_PATH=/doc/program/smart/soul-admin.jar
  3. # read -p ":" PROJECT_PATH
  4. # echo "你输入的数是:$PROJECT_PATH"
  5. echo 如果下面的参数都在文件中写死了那就直接回车跳过设置
  6. read -p "请输入项目路径(+jar名.jar):" PROJECT_PATH
  7. read -p "请设置端口:" PROJECT_PORT
  8. read -p "请设置配置文件:" PROJECT_PROPERTIES
  9. # 设置环境参数
  10. JAVA_OPTS=" -Xms512m "
  11. # -XX:+UseConcMarkSweepGC -XX:+UseParNewGC || -XX:+UseParallelGC -XX:+UseParallelOldGC
  12. JAVA_OPTS="${JAVA_OPTS} -Xmx1024m -Xmn512m -XX:+UseParallelGC -XX:+UseParallelOldGC "
  13. JAVA_OPTS="${JAVA_OPTS} -Dfile.encoding=UTF-8"
  14. # 设置默认值
  15. if [ ! $PROJECT_PATH ]; then
  16. PROJECT_PATH="test.jar"
  17. fi
  18. if [ ! $PROJECT_PORT ]; then
  19. SERVER_PORT=" --server.port=1234"
  20. else
  21. SERVER_PORT=" --server.port=${PROJECT_PORT}"
  22. fi
  23. if [ ! $PROJECT_PROPERTIES ]; then
  24. SERVER_PROPERTIES="--spring.profiles.active=prod"
  25. else
  26. SERVER_PROPERTIES="--spring.profiles.active=${PROJECT_PROPERTIES}"
  27. fi
  28. # shutdown
  29. pid=`ps -ef|grep $PROJECT_PATH | grep -v grep | awk '{print $2}'`
  30. kill -9 $pid
  31. echo "$pid进程终止成功"
  32. sleep 1
  33. # startUp
  34. sleep 2
  35. # 判断jar包文件是否存在,如果存在启动jar包,并时时查看启动日志
  36. if test -e $PROJECT_PATH
  37. then
  38. echo '文件存在,开始启动此程序...'
  39. # 启动jar包,指向日志文件,2>&1 & 表示打开或指向同一个日志文件
  40. echo "nohup java -jar $JAVA_OPTS "$PROJECT_PATH" $SERVER_PORT $SERVER_PROPERTIES >/dev/null 2>&1 &"
  41. nohup java -jar $JAVA_OPTS $PROJECT_PATH $SERVER_PORT $SERVER_PROPERTIES >/dev/null 2>&1 &
  42. echo "$PROJECT_PATH 启动成功..."
  43. else
  44. echo "$PROJECT_PATH 文件不存在,请检查。"
  45. fi

Start

  1. #!/bin/bash
  2. # PROJECT_PATH=/doc/program/smart/soul-admin.jar
  3. # read -p ":" PROJECT_PATH
  4. # echo "你输入的数是:$PROJECT_PATH"
  5. echo 如果下面的参数都在文件中写死了那就直接回车跳过设置
  6. read -p "请输入项目路径(+jar名.jar):" PROJECT_PATH
  7. read -p "请设置端口:" PROJECT_PORT
  8. read -p "请设置配置文件:" PROJECT_PROPERTIES
  9. # 设置环境参数
  10. JAVA_OPTS=" -Xms512m "
  11. # -XX:+UseConcMarkSweepGC -XX:+UseParNewGC || -XX:+UseParallelGC -XX:+UseParallelOldGC
  12. JAVA_OPTS="${JAVA_OPTS} -Xmx1024m -Xmn512m -XX:+UseParallelGC -XX:+UseParallelOldGC "
  13. JAVA_OPTS="${JAVA_OPTS} -Dfile.encoding=UTF-8"
  14. # 设置默认值
  15. if [ ! $PROJECT_PATH ]; then
  16. PROJECT_PATH="test.jar"
  17. fi
  18. if [ ! $PROJECT_PORT ]; then
  19. SERVER_PORT=" --server.port=1234"
  20. else
  21. SERVER_PORT=" --server.port=${PROJECT_PORT}"
  22. fi
  23. if [ ! $PROJECT_PROPERTIES ]; then
  24. SERVER_PROPERTIES="--spring.profiles.active=prod"
  25. else
  26. SERVER_PROPERTIES="--spring.profiles.active=${PROJECT_PROPERTIES}"
  27. fi
  28. # startUp
  29. sleep 2
  30. # 判断jar包文件是否存在,如果存在启动jar包,并时时查看启动日志
  31. if test -e $PROJECT_PATH
  32. then
  33. echo '文件存在,开始启动此程序...'
  34. # 启动jar包,指向日志文件,2>&1 & 表示打开或指向同一个日志文件
  35. echo "nohup java -jar $JAVA_OPTS "$PROJECT_PATH" $SERVER_PORT $SERVER_PROPERTIES >/dev/null 2>&1 &"
  36. nohup java -jar $JAVA_OPTS $PROJECT_PATH $SERVER_PORT $SERVER_PROPERTIES >/dev/null 2>&1 &
  37. echo "$PROJECT_PATH 启动成功..."
  38. else
  39. echo "$PROJECT_PATH 文件不存在,请检查。"
  40. fi

Stop

  1. #!/bin/bash
  2. # PROJECT_PATH=/doc/program/smart/soul-admin.jar
  3. # read -p ":" PROJECT_PATH
  4. # echo "你输入的数是:$PROJECT_PATH"
  5. echo jps -l 查看
  6. read -p "请输入项目路径(+jar名.jar):" PROJECT_PATH
  7. # 设置默认值
  8. if [ ! $PROJECT_PATH ]; then
  9. PROJECT_PATH="test.jar"
  10. fi
  11. # shutdown
  12. pid=`ps -ef|grep $PROJECT_PATH | grep -v grep | awk '{print $2}'`
  13. kill -9 $pid
  14. echo "$pid进程终止成功"
  15. sleep 1