bootstrap.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/bash
  2. ######################################################
  3. # Copyright 2019 Pham Ngoc Hoai
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. # Repo: https://github.com/tyrion9/spring-boot-startup-script
  18. #
  19. ######### PARAM ######################################
  20. cd ./target
  21. JAVA_OPT= #"-Xmx1024m"
  22. JARFILE=`ls -1r *.jar 2>/dev/null | head -n 1`
  23. PID_FILE=pid.file
  24. RUNNING=N
  25. PWD=`pwd`
  26. ######### DO NOT MODIFY ########
  27. if [ -f $PID_FILE ]; then
  28. PID=`cat $PID_FILE`
  29. if [ ! -z "$PID" ] && kill -0 $PID 2>/dev/null; then
  30. RUNNING=Y
  31. fi
  32. fi
  33. start()
  34. {
  35. if [ $RUNNING == "Y" ]; then
  36. echo "Application already started"
  37. else
  38. if [ -z "$JARFILE" ]
  39. then
  40. echo "ERROR: jar file not found"
  41. else
  42. nohup java $JAVA_OPT -Djava.security.egd=file:/dev/./urandom -jar $PWD/$JARFILE --spring.config.location=../src/main/resources/application.yml > nohup.out 2>&1 &
  43. echo $! > $PID_FILE
  44. echo "Application $JAVA_OPT $JARFILE starting..."
  45. tail -f nohup.out
  46. fi
  47. fi
  48. }
  49. stop()
  50. {
  51. if [ $RUNNING == "Y" ]; then
  52. kill -9 $PID
  53. rm -f $PID_FILE
  54. echo "Application stopped"
  55. else
  56. echo "Application not running"
  57. fi
  58. }
  59. restart()
  60. {
  61. stop
  62. start
  63. }
  64. case "$1" in
  65. 'start')
  66. start
  67. ;;
  68. 'stop')
  69. stop
  70. ;;
  71. 'restart')
  72. restart
  73. ;;
  74. *)
  75. echo "Usage: $0 { start | stop | restart }"
  76. exit 1
  77. ;;
  78. esac
  79. exit 0