bootstrap.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. JAVA_OPT=-Xmx1024m
  21. JARFILE=`ls -1r *.jar 2>/dev/null | head -n 1`
  22. PID_FILE=pid.file
  23. RUNNING=N
  24. PWD=`pwd`
  25. ######### DO NOT MODIFY ########
  26. if [ -f $PID_FILE ]; then
  27. PID=`cat $PID_FILE`
  28. if [ ! -z "$PID" ] && kill -0 $PID 2>/dev/null; then
  29. RUNNING=Y
  30. fi
  31. fi
  32. start()
  33. {
  34. if [ $RUNNING == "Y" ]; then
  35. echo "Application already started"
  36. else
  37. if [ -z "$JARFILE" ]
  38. then
  39. echo "ERROR: jar file not found"
  40. else
  41. nohup java $JAVA_OPT -Djava.security.egd=file:/dev/./urandom -jar $PWD/$JARFILE > nohup.out 2>&1 &
  42. echo $! > $PID_FILE
  43. echo "Application $JARFILE starting..."
  44. tail -f nohup.out
  45. fi
  46. fi
  47. }
  48. stop()
  49. {
  50. if [ $RUNNING == "Y" ]; then
  51. kill -9 $PID
  52. rm -f $PID_FILE
  53. echo "Application stopped"
  54. else
  55. echo "Application not running"
  56. fi
  57. }
  58. restart()
  59. {
  60. stop
  61. start
  62. }
  63. case "$1" in
  64. 'start')
  65. start
  66. ;;
  67. 'stop')
  68. stop
  69. ;;
  70. 'restart')
  71. restart
  72. ;;
  73. *)
  74. echo "Usage: $0 { start | stop | restart }"
  75. exit 1
  76. ;;
  77. esac
  78. exit 0