run.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/bash
  2. #设置jar文件名
  3. APP_NAME=blade-api.jar
  4. #使用说明,用来提示输入参数
  5. usage() {
  6. echo "Usage: sh 执行脚本.sh [start|stop|restart|status]"
  7. exit 1
  8. }
  9. #检查程序是否在运行
  10. is_exist(){
  11. pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}' `
  12. #如果不存在返回1,存在返回0
  13. if [ -z "${pid}" ]; then
  14. return 1
  15. else
  16. return 0
  17. fi
  18. }
  19. #启动方法
  20. start(){
  21. is_exist
  22. if [ $? -eq "0" ]; then
  23. echo "${APP_NAME} is already running. pid=${pid} ."
  24. else
  25. cp jar/$APP_NAME $APP_NAME
  26. nohup java -Xms1024m -Xmx1024m -jar $APP_NAME --spring.profiles.active=test > /dev/blade/null 2>&1 &
  27. fi
  28. }
  29. #停止方法
  30. stop(){
  31. is_exist
  32. if [ $? -eq "0" ]; then
  33. kill -9 $pid
  34. else
  35. echo "${APP_NAME} is not running"
  36. fi
  37. }
  38. #输出运行状态
  39. status(){
  40. is_exist
  41. if [ $? -eq "0" ]; then
  42. echo "${APP_NAME} is running. Pid is ${pid}"
  43. else
  44. echo "${APP_NAME} is NOT running."
  45. fi
  46. }
  47. #重启
  48. restart(){
  49. stop
  50. start
  51. }
  52. #根据输入参数,选择执行对应方法,不输入则执行使用说明
  53. case "$1" in
  54. "start")
  55. start
  56. ;;
  57. "stop")
  58. stop
  59. ;;
  60. "status")
  61. status
  62. ;;
  63. "restart")
  64. restart
  65. ;;
  66. *)
  67. usage
  68. ;;
  69. esac